1、python的时间函数
Unix时间戳是一个浮点值和整型值,表示自1970年1月1日午夜0点(UTC)以来的秒数
datetime:包含一些整型值,保存在year、month、day、hour、minute、second属性中
timedelta:表示一段时间,不是一个特定的时刻
time.time():返回浮点值,表示当前时刻的Unix纪元时间戳
time.sleep(seconds):程序暂停secondes指定的秒数
datetime.datetime(year,month,day,hour,minute,second):返回指定时刻的datetime对象
datetime.datetime.now():返回当前时刻的datetime对象
datetime.datetime.fromtimestamp(epoch):返回epoch时间戳表示的时刻的datetime对象
datetime.timedelta(weeks,days,hours,minutes,seconds,milliseconds,microseconds):返回一个表示一段时间的timedelta对象
total_seconds():返回timedelta对象表示的秒数
strftime(format):返回一个字符串,用format字符串中的定制格式表示datetime对象的时间
datetime.datetime.strptime(time_string,format):返回一个datetime对象,它的时刻由time_string指定,用format字符串参数来解析
2、创建线程 threading.Thread(target=待执行方法名称)
代码如下:
import threading
threadObj=threading.Thread(target=print,args=['cats','dogs','frogs'],kwargs={'sep':'&'}) #print是方法名称,args是print传入的参数值
threadObj.start() #启动线程
3、python启动其他程序 Popen()函数
subprocess是python自带的模块,可直接导入
代码如下:
import subprocess
subprocess.Popen('c:\\Windows\\System32\\calc.exe')
subprocess.Popen(['c:\\python37\\python.exe','hello.py'])