Question

First I have an Unix epoch time 1270787111.

Then based on this website: http://untangible.com/2009/01/covert-unix-epoch-dates-in-microsoft-excel-including-timezone-examples.html, I convert the number to be 40276.9758217592. Then I put the value into an Excel cell and convert it into "Date" format to be : 4/8/10 23:25 I do not know how this happens. How can the value 40926 be converted into 2010(year)04(month)08(day)? Is there any other programming way to convert an Unix epoch time into a human readable format time?

Was it helpful?

Solution 2

If you have the GNU coreutils date command, you can do this:

$ date -d @1270787111
Thu Apr  8 21:25:11 PDT 2010

If you'd rather do it in C, use localtime() or gmtime() to convert the time_t value 1270787111 to a struct tm, then use asctime() to convert that to a human-readable string. ctime(t) is equivalent to asctime(localtime(t)). This assumes that your C library represents time_t values as seconds since the Unix epoch (1970-01-01 00:00:00); POSIX guarantees this, but C does not.

strftime() takes a struct tm and converts it to a human-readable string, letting you control the format, rather than using the default "Thu Apr 8 21:25:11 2010\n" format imposed by ctime() and asctime() (yes, the default format includes a trailing newline).

Be sure to read the documentation for these functions. They require a lot of pointer manipulation.

OTHER TIPS

My personal favorite is

perl -E 'say scalar gmtime 1270787111'

Excel starts dates from January 0, 1900 (yes, January 0). From this link.

The integer portion of the number, ddddd, represents the number of days since 1900-Jan-0

The date you end up with 40,276 days after 1/0/1900.

There are usually built-in functions in many programming languages (C/C++, Perl, PHP, etc.) for handling UNIX epoch timestamps. It really just depends on what language you're using as to what methods/functions you would call. Here's a link that shows some examples in C.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top