1. 程式人生 > >python Timestamp、Datetime、UTC時間之間轉換練習

python Timestamp、Datetime、UTC時間之間轉換練習

#coding=utf-8
import time
import datetime
def get_prev_timestamp(tart_ts, interval = 3):
    start_array = datetime.datetime.utcfromtimestamp(start_ts)
    start_array = start_array + datetime.timedelta(hours=8)
    prev_time = (start_array - datetime.timedelta(days = interval))
    prev_ts = int(time.mktime(prev_time.timetuple()))

    return 
prev_ts def get_end_timestamp(start_ts, interval = 30): start_date = datetime.datetime.utcfromtimestamp(start_ts) start_date = start_date + datetime.timedelta(hours=8) end_date = start_date + datetime.timedelta(minutes = interval) end_ts = int(time.mktime(end_date.timetuple())) return
end_ts def get_seven_day_ago( day = 7): human = {'d':86400 } now = int(time.time()) ts = now - day * human['d'] return str(ts) start_ts = time.time() print get_seven_day_ago()