《像计算机科学家一样思考Python》练习5-1

题目

编写一个脚本,用time.time()读取从1970纪元到当前的格林尼治时间,并转换为一天中的小时数、分钟数、秒数,以及从纪元起到现在的天数

总结

当前时间是22点多,但是计算出来的小时数是14,开始以为自己计算错了,后来发现22点是北京时间(东八区),14是对的

import time
now = time.time() #返回格林尼治时间 1970纪元后经过的浮点秒数
print(now)
day = now // (60 * 60 * 24)
print('day is ', int(day))
second = now % (60 * 60 * 24)
print('second is ', int(second))
minute = second / 60
print('minute is ', int(minute))
hour = minute / 60
print('hour is ', int(hour))
print(time.localtime(time.time()))

你可能感兴趣的:(Python)