赞
踩
- import time
- print(time.time())
- print(round(time.time(),2))#四舍五入获取当前时间
- #超级秒表
- print('Press ENTER to begin.Afterwards, press ENTER to "click" the stopswatch.')
- print('Press Ctrl-C to quit.')
-
- input()
- print('Started.')
- startTime = time.time()
- lastTime = startTime
-
- lapNum = 1
-
- try:
- while True:
- input()
- lapTime = round(time.time() - lastTime,2)
- totalTime = round(time.time() - startTime,2)
- print('Lap #%s: %s(%s)'%(lapNum,lapTime,totalTime),end ='')
- lapNum += 1
- lastTime = time.time()
- except KeyboardInterrupt:
- print('\nDone')

-
- import datetime
-
- print(datetime.datetime.now())
-
- dt = datetime.datetime.now()
- print(dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second)#dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second(年、月、日、时、分、秒)
- print(datetime.datetime.fromtimestamp(time.time()))
-
- if datetime.datetime(2017,12,21,12,12,12) >= datetime.datetime.fromtimestamp(time.time()):
- print("True")
- else:
- print("False")
-
- delta = datetime.timedelta(weeks = 2,days = 2,hours = 12,minutes = 50,seconds = 45)
-
- print(delta)
- print(str(delta))
-
- print(delta.days,delta.seconds,delta.microseconds)
-
- print(delta.total_seconds())
算术运算符可以用于对datetime值进行日期运算
- dtt = datetime.datetime.now() + delta
-
- print(dtt)
-
- print(datetime.datetime.now() - delta)
-
- print(delta*2)
- print(delta*2.14)
-
- print(delta/2)
- print(delta/2.14)
- startRunTime = datetime.datetime(2017,6,22,14,36,0)
- while datetime.datetime.now() < startRunTime:
- time.sleep(1)
- print("startRunTime......")
- #datetime.datetime.now()可以被替换为datetime.datetime(2015,6,18,13,25,34)
- print(datetime.datetime.now().strftime('%Y/%m/%d %I:%M:%S %R'))
- print(datetime.datetime.now().strftime('%Y/%m/%d %I:%M:%S %p'))
-
- print(datetime.datetime.now().strftime('%Y/%m/%d %R'))
-
- print(datetime.datetime.now().strftime('%V'))
- print(datetime.datetime.now().strftime('%W'))
- print(datetime.datetime.now().strftime('%h'))
- print(datetime.datetime.now().strftime('%T'))
-
- print(datetime.datetime.now().strftime('%x'))
print(datetime.datetime.strptime('2017/06/22 07:16:14 PM','%Y/%m/%d %I:%M:%S %p'))
- import threading
-
- print('Starting of program.')
-
-
- def takeANap():
- time.sleep(5)
- print('Wake up!')
-
- threadObj = threading.Thread(target = takeANap)#调用threading.Thread()函数,并传入关键字参数target=takeANap,而不是target=takeANap(),创建threadObj对象
- threadObj.start()#创建新的线程,并开始在新的线程中执行目标函数
-
- print('End of program.')
- print('Cats','Dags','Frogs',sep = ' & ')
- threadObjOne = threading.Thread(target = print,args = ['Cats','Dags','Frogs'],kwargs = {'sep':' & '})
- threadObjOne.start()
-
从python启动其他程序
- import subprocess
- subprocess.Popen('C:\\Users\\Nick\\AppData\\Roaming\\360se6\\Application\\360se.exe')
- #返回值是一个Popen对象,<subprocess.Popen object at 0x02C007B0>
- import subprocess
- sunprocessObj = subprocess.Popen('C:\\Users\\Nick\\AppData\\Roaming\\360se6\\Application\\360se.exe')
- print(sunprocessObj.poll())
- print(sunprocessObj.wait())
- time.sleep(5)
- print(sunprocessObj.poll())
subprocess.Popen(['C:\\Program Files (x86)\\Sublime Text3\\sublime_text.exe','C:\\Users\\Nick\\Desktop\\solr方法.txt'])
subprocess.Popen(['start','C:\\Users\\Nick\\Desktop\\solr方法.txt'],shell=True)
- #倒计时
- timeLeft = 60
-
- while timeLeft > 0:
- print(timeLeft,end = ' ')
- time.sleep(1)
- timeLeft = timeLeft - 1
- subprocess.Popen(['start','C:\\Users\\Nick\\Desktop\\感觉静谧.mp3'],shell=True)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。