Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strftime %F does not work on Windows

I am trying to compile this simple example on Windows. When I use %F, which is a shortcut for the longer form of %Y-%m-%d, the process aborts with no error message. On Linux, it works fine as in this live example shows on ideone.com. Any ideas?

#include <stdio.h> 
#include <time.h>

int main ()
{
   time_t rawtime;
   struct tm * timeinfo;
   char buffer [80];

   time (&rawtime);
   timeinfo = localtime (&rawtime);

   strftime (buffer,80,"Now it's %F.",timeinfo);
   puts (buffer);

   return 0;
}
like image 521
Engineer2021 Avatar asked Feb 13 '23 02:02

Engineer2021


1 Answers

%F is C99, see strftime on man7 or compare the C99 and C90 standards yourself.

strftime in the VS2013 library and earlier are not C99-conformant, as they do not accept that format-specifier: MSDN VS2013 strftime page
Maybe the next version will add it, as the format is not used for anything else yet...

Just use the format it's a shortcut to directly, that's C89 and VS2013 conformant: %Y-%m-%d

Quote for what happens with an invalid format specifier passed to strftime from the C standard:

6 If a conversion specifier is not one of the above, the behavior is undefined.

like image 81
Deduplicator Avatar answered Feb 15 '23 10:02

Deduplicator