开发者

Convert seconds to date from Jan 01 1901 in unix/linux

开发者 https://www.devze.com 2023-01-24 09:08 出处:网络
im trying to convert a time stamp in seconds from Jan 01 1901 to the current date. for example, time stamp 3465468225 translate to a date开发者_运维问答 in 2010.does anyone know of a way to do this i

im trying to convert a time stamp in seconds from Jan 01 1901 to the current date.

for example, time stamp 3465468225 translate to a date开发者_运维问答 in 2010. does anyone know of a way to do this in unix/linux? thanks.


In R, it is as simple as this:

> as.POSIXct(3465468225, origin="1901-01-01")
[1] "2010-10-25 15:03:45 CDT"  
>  

This uses appropriate wrappers around C-level calls gmtime() / localtime() plus time formatting via strftime().


On GNU and POSIX systems you can obtain the date string using seconds since Epoch (1970-01-01 00:00:00 UTC) as:

$ date --date=@1289495920
Thu Nov 11 12:18:40 EST 2010

You should handle the offset since Jan 01 1901 yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号