20161209
The date
command is Gnu coreutils [^ 1].
[^ 1]: For BSD date date -r 1481122800" +% Y-% M-% d% T "
, date -j -f"% Y-% m-% d% T "" 2016-12 -08 00:00:00 "" +% s "
date => epoch
$ date "+%s" -d"2016-12-08 00:00:00"
1481122800
$ perl -MTime::Local -le 'print timelocal(0,0,0,8,12 -1,2016)'
1481122800
$ python -c 'import datetime ; print (datetime.datetime(2016,12,8,0,0,0).strftime("%s"))'
1481122800
It's okay because the treatment of the year of timelocal
has been talked about.
epoch => date
$ date "+%Y-%m-%d %T" -d@1481122800
2016-12-08 00:00:00
$ perl -MPOSIX -le 'print strftime "%Y-%m-%d %T", localtime(1481122800)'
2016-12-08 00:00:00
$ python -c 'import datetime ; print (datetime.datetime.fromtimestamp(1481122800))'
2016-12-08 00:00:00
about.
Python calls the strftime () function of the platform's C library, and its implementation often varies from platform to platform, so the overall supported format symbols vary from platform to platform. See the strftime (3) documentation to see all of the format symbols supported by the platform.
So, there are some environments that don't implement % s
or% N
.
memo
import time
from datetime import datetime as dt
print (int(time.mktime(dt(2016,12,8,0,0,0).timetuple())))
Recommended Posts