因為最近寫 Python 實在太常用到這兩種方法了

所以順便記錄一下

Unix Timestamp to String

import datetime
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')

String to Unix Timestamp

import time
import datetime
str = "2014-01-30 21:44:14"
ts = time.mktime(datetime.datetime.strptime(str, "%Y-%m-%d %H:%M:%S").timetuple())