求当前的时分秒

totalSeconds = int(time.time())  # 当前时间距离1970年0时所逝去的秒数(浮点数强制转换为整数)

从总秒数中求余获得【今天逝去的秒数】,不足一天的秒数,求余(60 * 60 * 24)

todaySeconds = totalSeconds % (60 * 60 * 24)

今天逝去了多少小时=【今天逝去的秒数】包含多少完整的3600秒

nowHours = todaySeconds // (60 * 60)
nowHours += 8 % 24  # 东八区时差弥补

当前分钟数 = 【今天逝去的秒数】中不足一小时的秒数,再看其中包含多少完整的60秒

nowMinutes = todaySeconds % 3600 // 60

当前秒数 = 【今天逝去的秒数】中不足60秒的,即为当前秒数

nowSeconds = totalSeconds % 60

print("当前时间为:%d:%d:%d" % (nowHours, nowMinutes, nowSeconds))

猜你喜欢

转载自blog.csdn.net/a__rong/article/details/78442162
今日推荐