#Author:lei
#時間的3種表現形式 1.時間戳 2.格式化的時間字符串 3.元組 struc_time 9個元素
#夏令時 比標準時間提前1小時
import time
'''
print(time.time()) #獲取時間戳
x=time.time() #當前時間與unix誕生年的時間差
print(x/3600/24/365) #換算成多少年 x/3600秒/24小時/365天
time.timezone #時區
time.altzone #夏令時 要比時區早1小時
time.daylight #是否使用夏令時 0表示不使用
time.time() #獲取時間戳
time.sleep(1) #休眠1秒
print(time.gmtime()) #默認傳入utc時間 元組 gmtime(timestamp時間戳)
print(time.localtime(123653652)) #默認傳入本地時間 元組 localtime(timestamp時間戳)
x=time.localtime()
print(x)
print(x.tm_year) #獲取年份
print(x.tm_yday) #獲取哪一天
print(time.mktime(x)) #時間 元組轉換成時間戳
'''
x=time.localtime()
#print(time.strftime("%Y-%m-%d %H:%M:%S",x)) #時間 格式化輸出 元組轉換成字符串
#print(time.strptime('2018-11-23 01:01:49',"%Y-%m-%d %H:%M:%S")) #時間,字符串轉換成元組
y=time.strptime('2018-11-23 01:01:49',"%Y-%m-%d %H:%M:%S")
#strftime("格式",struct_time) ---> “格式化的字符串”
#striptime("格式化字符串","格式")--->struct_time元組
'''
x.tm_year=2018
x.tm_mon=11
x.tm_day=23
x.tm_hour=01
x.tm_min=01
x.tm_sec=49
'''
#print(time.asctime(y)) #元組按 %a 星期 %b月份 %d天 %H:%M:%S %Y 這種字符串來顯示
#print(time.ctime(1956115.256)) #時間戳 按 %a 星期 %b月份 %d天 %H:%M:%S %Y 這種字符串來顯示
#datetime
import datetime
print(datetime.datetime.now()) #獲取當前時間
print(datetime.datetime.now()+datetime.timedelta(3)) #+3天后的時間
print(datetime.datetime.now()+datetime.timedelta(-3)) #-3天前的時間
print(datetime.datetime.now()+datetime.timedelta(hours=3)) #+3個小時以後的時間
print(datetime.datetime.now()+datetime.timedelta(hours=-3)) #-3個小時以前的時間
print(datetime.datetime.now()+datetime.timedelta(minutes=30)) #+30分鍾以後的時間
print(datetime.datetime.now()+datetime.timedelta(minutes=-30)) #-30分鍾以前的時間