m
Write a c program to print date and time
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
m
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted May 31, 2023, 5:58 AM EDT
#include #include int main() { // Get the current time time_t currentTime = time(NULL); // Convert the current time to the local time struct tm *localTime = localtime(¤tTime); // Print the date and time printf("Current Date and Time: %s", asctime(localTime)); return 0; }Rupesh KahaneRank #136 · 16.4K reputationPosted May 31, 2023, 6:11 AM EDT
#include
#include
#include
int main()
{
time_t t;
t = time(NULL);
struct tm tm;
tm = *localtime(&t);
printf("Current Time: %d:%d:%d", tm.tm_hour, tm.tm_min, tm.tm_sec);
// output Current Time: 3:40: 29
printf("Current Date: %d-%d-%d", tm.tm_mday, tm.tm_mon+1, tm.tm_year+1900);
// output Current Date: 31-05-2023
getch();
return 0;
}