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

后端 未结 6 661
余生分开走
余生分开走 2021-01-30 13:23

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 Exc

6条回答
  •  天涯浪人
    2021-01-30 14:02

    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.

提交回复
热议问题