简体   繁体   中英

How do I convert a Unix epoch timestamp into a human readable date/time in Excel?

I have Excel documents containing Unix epoch timestamps from a Java application. I'd like to see what they translate to and represent them as human readable dates inside of Excel.

For example, the following long: 1362161251894 should evaluate to something readable like: 01 Mar 2013 11:07:31,894

I'm assuming I can create a formula for this, but I'm not sure how. Thanks!

Yes, you can create a formula to do this for you. Java and Unix/Linux count the number of milliseconds since 1/1/1970 while Microsoft Excel does it starting on 1/1/1900 for Windows and 1/1/1904 for Mac OS X. You would just need to do the following to convert:

For GMT time on Windows

=((x/1000)/86400)+(DATEVALUE("1-1-1970") - DATEVALUE("1-1-1900"))

For GMT time on Mac OS X

=((x/1000)/86400)+(DATEVALUE("1-1-1970") - DATEVALUE("1-1-1904"))

For local time on Windows (replace t with your current offset from GMT)

=(((x/1000)-(t*3600))/86400)+(DATEVALUE("1-1-1970") - DATEVALUE("1-1-1900"))

For local time on Mac OS X (replace t with your current offset from GMT)

=(((x/1000)-(t*3600))/86400)+(DATEVALUE("1-1-1970") - DATEVALUE("1-1-1904"))

In your specific case it looks like you are in a Mountain Time (GMT offset of 7 ). So if I paste your value given of 1362161251894 in a new Excel spreadsheet in cell A1 and then paste the following formula, I get a result of 41333.46356, which if I then tell Excel to format as a Date (press ctrl+1 on the cell) is: 2/28/13 11:07 AM

=(((A1/1000)-(7*3600))/86400)+(DATEVALUE("1-1-1970") - DATEVALUE("1-1-1900"))

This seems to be answered here ,

=(A1/86400)+25569

Epoch time was provided in milliseconds ( 1523060201838 ). User is looking to Convert for NY Time Zone ( GMT -04:00 or DST -14400 ).

Cell A1 on Excel has the 13 digit value epoch time.

((A1/1000)-14400)/86400 + 25569

converts to 4/6/18 8:16 PM (after you format cell as Date).

I have found that the easiest formulas to remember and read are these:

Convert from Unix/Epoch timestamp to date in Excel (assuming timestamp is in A2):

=(A2/86400)+DATE(1970,1,1)

This will generate the GMT Excel time value. You then need to set the format for the cell to one of the date formats, or create your own custom format. I tend to use either:

dd-mmm-yy                --> gives 05-Oct-18
dd-mmm-yyyy hh:mm:ss     --> gives 05-Oct-2018 09:45:12

Convert from date to Epoch timestamp (assuming date is in A2):

=(A2-DATE(1970,1,1))*86400

I have found that this page is pretty helpful: Extendoffice excel-timestamp-to-date

Note: If you need to adjust to local time from GMT (New York as an example), add the difference at the end. The following show a -5 hour offset.

=(A2/86400)+DATE(1970,1,1)+(-5/24)

Excel expresses days as whole values and times as fractional values. Therefore, if the epoch time was provided in milliseconds since 1-1-1970 from UNIX, then we want to divide by the number of milliseconds in a year and add Excel's representation of 1-1-1970 to provide the human readable UTC time. If your value is in cell A1, then Excel would need:

=A1/86400/1000+DATEVALUE("1-1-1970")

Note you can drop the /1000 if your epoch time was in seconds rather than milliseconds. To convert to local time, where 't' is your local UTC offset (remember to use a negative value if you have a negative UTC offset), you can add/subtract the UTC offset:

=A1/86400/1000+DATEVALUE("1-1-1970")+t/24

Note that your UTC offset may vary based on whether daylight saving time is observed in your location, making this an incomplete solution for showing local times throughout the year in a single spreadsheet.

Try

=(A2/86400)+DATE(1970,1,1)+TIME(5,30,0)

it will help for local timing like India is GMT + 5:30.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM