python中時間戳,字符串,時間元組之間的轉換

把時間戳,去掉日時分秒,保留年月,方便判斷是否是本月

def get_month_timestamp(timestamp):
    #時間戳轉爲元組
    now = time.localtime(timestamp)
    #元組轉爲字符串
    monthStr = time.strftime("%Y-%m-00 00:00:00", now)
    #字符串轉爲元組
    monthTuple = time.strptime(monthStr, '%Y-%m-00 00:00:00')
    #元組轉爲時間戳
    return time.mktime(monthTuple)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章