标签:pre alt author usr amp 程序等待 localtime date() 计算
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "ziya"
# Date: 2018-08-16
import time
# 时间戳
t = time.time()
print('时间戳:', t)
# 时间元祖
t1 = time.gmtime() # UTC时区
t2 = time.localtime() # 本地时区
# 转时间戳
t3 = time.mktime(t1)
print('时间元祖取年:', t1.tm_year)
print('时间元祖转时间戳:', t3)
# 时间字符串
print('时间元祖转字符串:', time.strftime('%Y-%m-%d %X', t2))
print('时间字符串转元祖:', time.strptime('1996-10-19', '%Y-%m-%d'))
# 睡
print('让程序等待(当前线程):', time.sleep(3))
import datetime
d = datetime.datetime.now()
print(d.year)
print(d.month)
print(d.day)
print(d.date())
d2 = datetime.timedelta(4)
print(d + d2)
d3 = datetime.timedelta(hours=4)
print(d + d3)
import datetime
d1 = datetime.datetime.now()
d2 = datetime.timedelta(4)
print(d1 + d2)
d3 = datetime.timedelta(hours=4)
print(d1 + d3)
标签:pre alt author usr amp 程序等待 localtime date() 计算
原文地址:https://www.cnblogs.com/xjmlove/p/10337729.html