<Python> unixtimeをepoctimeに変換

unixtimeepoctimeに変換。

In [3]: import dateutil.parser

In [4]: import time

In [5]: day = '03-JAN-2016 16:39'

In [6]: dateutil.parser.parse(day)
Out[6]: datetime.datetime(2016, 1, 3, 16, 39)

In [7]: type(dateutil.parser.parse(day))
Out[7]: datetime.datetime

In [8]: dateutil.parser.parse(day).timetuple()
Out[8]: time.struct_time(tm_year=2016, tm_mon=1, tm_mday=3, tm_hour=16, tm_min=39, tm_sec=0, tm_wday=6, tm_yday=3, tm_isdst=-1)

In [9]: time.mktime(dateutil.parser.parse(day).timetuple())
Out[9]: 1451806740.0

In [10]: int(time.mktime(dateutil.parser.parse(day).timetuple()))
Out[10]: 1451806740

dateutilマニュアル

dateutil - powerful extensions to datetime — dateutil 2.4.2 documentation

参考(他のやり方)

日付フォーマット(datetime⇔文字列) – Python Snippets

昔のポスト

nekoyukimmm.hatenablog.com