A pure C solution using only standard C functions:
#include <stdio.h> #include <time.h> int main(void) { time_t now = time(NULL); struct tm *now_tm = gmtime(&now); char iso_8601[] = "YYYY-MM-DDTHH:MMZ"; /* init just to get the right length */ strftime(iso_8601, sizeof iso_8601, "%FT%RZ", now_tm); puts(iso_8601); return 0; }
source share