Epoch in Python

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

datetime strftime

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.

Source

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

Epoch in Python
Quadtree in Python --2
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Sorted list in Python
Daily AtCoder # 36 in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Edit fonts in Python
Singleton pattern in Python
File operations in Python
Read DXF in python
Daily AtCoder # 53 in Python
Key input in Python
Use config.ini in Python
Daily AtCoder # 33 in Python
Solve ABC168D in Python
Logistic distribution in Python
Daily AtCoder # 7 in Python
One liner in Python