文字列の日付と時刻をタイムスタンプに変換する
# '2015-08-28 16:43:37.283' --> 1440751417
def string2timestamp(strValue):
d = datetime.datetime.strptime(strValue, "%Y-%m-%d %H:%M:%S")
t = d.timetuple()
timeStamp = int(time.mktime(t))
timeStamp = float(str(timeStamp) + str("%06d" % d.microsecond))/1000000
return timeStamp
文字列の日付と時刻に変換されたタイムスタンプ
# 1440751417 --> '2015-08-28 16:43:37'
def timestamp2string(timeStamp):
d = datetime.datetime.fromtimestamp(timeStamp)
str1 = d.strftime("%Y-%m-%d %H:%M:%S")
return str1
参照:リンクの説明を追加