问题
C has a predefined macro __DATE__
, that shows the date of the compiled source file .
The date is displayed in the format "Mmm dd yyyy" .
Is there any way to be formatted this date, using macros ?
In this format "yyyy Mmm dd".
Instead of being :
Jul 19 2013
Should be :
2013 Jul 19
回答1:
In C you could have a macro that generates a compound literal on the fly that has the order that you like, something like
#define FDATE (char const[]){ __DATE__[7], __DATE__[8], ..., ' ', ... , '\0' }
in all places where it matters your optimizer should be able to handle this efficiently.
回答2:
Here's a true hack:
union {
const char DOUBLE_DATE[18];
const char PAD[19];
} DATE_HELPER = { __DATE__ " " __DATE__ };
const char *MY_DATE = DATE_HELPER.DOUBLE_DATE + 7;
来源:https://stackoverflow.com/questions/17739390/different-format-of-date-macro