#include <stdio.h>
#include <time.h>
int main()
{
time_t now;
struct tm *d;
char li[18];
time(&now);
d = localtime(&now);
strftime(li, 18, "%D %T", d);
printf("%s\n", li);
return 0;
}
Getting time in C in windows
Started by sourlemon, Dec 17 2009 11:25 PM
2 replies to this topic
#1
Posted 17 December 2009 - 11:25 PM
I'm using netbeans to program C in windows. I've programmed it in Linux, and it worked. But I'm having trouble getting the time to work correctly in windows. This is the code.
|
|
|
#2
Posted 18 December 2009 - 05:44 AM
Well, based on this reference, your format specifier is invalid. It will be case sensitive, and only uses lower-case d, and doesn't have a T specifier at all.
#3
Posted 18 December 2009 - 12:00 PM
That's interesting. I got the date format from the linux manual. Maybe that's why it only worked on linux. I'll give that a try. Thank you.


Sign In
Create Account


Back to top









