Frage

I have a 13 digit integer like (1384318800000) which is said to be unix format. I need this date in MM/DD/YYYY . There is no visual match in this (1384318800000) points to a date 11/13/2013 . Let me know if any one knows this conversion

War es hilfreich?

Lösung

With given time_t value (which is 1384318800000 in your case) you can initialise tm structure using localtime function and then format a string using strftime

Andere Tipps

You are looking for an epoch converter. If you google epoch time converter you can find some helpful resources. http://www.epochconverter.com/ is a website devoted to this, for example.

The value you've specified was given in Unix time in milliseconds. The strftime deals with epoch time which is specified in seconds format. You will have to divide the value with 1000 before you feed to time_t variable. After all time_t is defined as long.

time_t t = 1384245237000/1000;
char       buf[80];
strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", localtime(&t));
printf("%s\n", buf);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top