datetime - Convert Epoch timestamp to date format -
i have .json
file lots of documents, each document this:
{"_id":{"$oid":"54ff56116d"},"caption":{"created_time":"1421434541",....}
i need convert created_time
date format in each of documents.
do have idea?
since have 10-digit numbers created time, you're using 'unix timestamps', count seconds since epoch, 1970-01-01 00:00:00 +00:00 (midnight on morning of 1st january 1970 in utc or gmt time zone). if had 13-digit numbers, milliseconds since epoch, used in java. there other systems, plausible guess.
there lots of systems of functions convert such values dates. have c program using standard library functions used validate date:
$ timestamp 1421434541 1421434541 = fri jan 16 10:55:41 2015 $ timestamp -u 1421434541 1421434541 = fri jan 16 18:55:41 2015 $ timestamp -t '%y-%m-%d %h:%m:%s' -u 1421434541 1421434541 = 2015-01-16 18:55:41 $
(local time zone: us/pacific, aka america/los_angeles.)
the program uses strtol()
convert number in string long
, uses localtime()
or gmtime()
break struct tm
, , uses strftime()
format result.
the gnu date
command can used stuff too:
$ /usr/gnu/bin/date -d @1421434541 +'%y-%m-%d %h:%m:%s' 2015-01-16 10:55:41 $
since you've not identified host language, not possible tell use. pretty guaranteed whatever language choose, there'll code available handle conversion, though.
Comments
Post a Comment