python get today, yesterday, tomorrow's time timestamp

__name__ == IF '__main__':
Import datetime
Import Time

# get today's date
print ( "get today's date")
Today = datetime.date.today ()
Print (Today) # 2019-09-05
Print (of the type (Today)) # <type 'datetime.date'>
print ( "**" 10 *)

# last date
print ( "last date")
yesterday = Today - the datetime.timedelta (Days =. 1)
Print (yesterday) # 2019-09-04
print ( "**" 10 *)

# time tomorrow
print ( "time tomorrow")
tomorrow Today + = the datetime.timedelta (Days =. 1)
Acquire the datetime.timedelta + = Today (Days = 2)
Print (tomorrow) # 2019- 09-06
Print (Acquire) # 2019-09-07
Print ( "**"* 10)

# yesterday timestamp
print ( "start timestamp yesterday")
yesterday_start_time = int (time.mktime (time.strptime ( str (yesterday), '% Y-% m-% d')))
after print (yesterday_start_time) # 1567526400 converted 00:00:00 2019-09-04
Print ( "**" 10 *)

# end timestamp of last
print ( "end timestamp yesterday")
yesterday_end_time = int (time.mktime (the time.strptime (STR (Today), 'M-%%% Y-D')) ) --1
after print (yesterday_end_time) # 1567612799 converted 23:59:59 2019-09-04
print ( "**" * 10)

# start timestamp today
print ( "start timestamp today")
today_start_time + 1 = yesterday_end_time
Print after (today_start_time) # 1567612800 converted 00:00:00 2019-09-05
print ( "**" * 10)

# end today timestamp
print ( "end timestamp today")
today_end_time = int (time.mktime (Time. strptime (str (tomorrow), '%Y-%m-%d'))) - 1
After the print (today_end_time) # 1567699199 converted 23:59:59 2019-09-05
print ( "**" * 10)

# tomorrow timestamp
print ( "tomorrow timestamp")
tomorrow_start_time = int (time.mktime (Time .strptime (STR (tomorrow), 'M-%%% Y-D')))
Print (tomorrow_start_time) # 1567699200 2019-09-06 00:00:00 after conversion
Print ( "**" 10 *)

# tomorrow end timestamp
print ( "tomorrow end timestamp")
tomorrow_end_time = int (time.mktime (the time.strptime (STR (Acquire), 'M-%%% Y-D'))) -. 1
Print (tomorrow_end_time) # 1567785599 after conversion 23:59:59 2019-09-06
print ( "**" 10 *)

# Last 24 hours
print ( "Last 24 hours")
TIME_NOW the time.time = ()
before_24 = int (TIME_NOW - 24 * 60 * 60)
Print (before_24)
Print ( "**"* 10)

# last week
print ( "last week")
time_now = time.time()
before_week = int(time_now - 7 * 24 * 60 * 60)
print(before_week)
print("**" * 10)


# 最近一月
print("最近一月")
time_now = time.time()
before_nonth = int(time_now - 30 * 24 * 60 * 60)
print(before_nonth)
print("**" * 10)

来源:https://blog.csdn.net/a961634066/java/article/details/100554487

Guess you like

Origin www.cnblogs.com/kaibindirver/p/12651135.html
Recommended