34
ISO 8601 Date Format Output
Here is the ANSI C code for getting the current date and printing it in ISO form:
// Create time storage structs
time_t now_t;
struct tm now;
// Read time value from system clock
time(&now_t);
//Convert to broken down time structure
now = *localtime(&now_t);
// Display formatted output
printf("%4d-%02d-%02d",
now.tm_year+1900,
now.tm_mon+1,
now.tm_mday);
If you prefer to use Perl, here is the code for presenting the current date and time in UTC form:
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);$t = sprintf "%4d-%02d-%02dT%02d:%02dZ\n", 1900+$year,$mon+1,$mday,$hour,$min;print ...
Get Developing Quality Metadata now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.