# 获取当前时间
import datetime
import time

now = datetime.datetime.now()

# 获取当前时间戳 20080808080808
now_time = now.strftime('%Y%m%d%H%M%S')
print('当前时间:',now_time)
# 获取当前日期
date_time = now.strftime("%Y%m%d")
print('当前日期:',date_time)
# 获取1970年距离当前秒数
now_time = int(time.mktime(time.strptime(now_time, "%Y%m%d%H%M%S")))
print('now:',now_time)

# 获取今天23:59:59
zeroToday = now - datetime.timedelta(hours=now.hour, minutes=now.minute, seconds=now.second,
                                     microseconds=now.microsecond)
lastToday = zeroToday + datetime.timedelta(hours=23, minutes=59, seconds=59)
lastToday = lastToday.strftime('%Y%m%d%H%M%S')
last = int(time.mktime(time.strptime(lastToday, "%Y%m%d%H%M%S")))
# 获取当前距离23:59:59的秒数
last_time = last - now_time
print("当前距离23:59:59的秒数:",last_time)

输出


当前时间: 20180709150228
当前日期: 20180709
now: 1531119748
当前距离23:59:59的秒数: 32251
打赏

发表评论

邮箱地址不会被公开。 必填项已用*标注