python datetime物件轉時間戳
阿新 • • 發佈:2019-02-06
import datetime,threadinglockObject = threading.Lock()def testTime(): global lockObject '''這個地方加個執行緒鎖,_strptime_time 執行緒不安全''' lockObject.acquire() t = datetime.datetime.now() timeStamp = time.mktime(t.timetuple()) lockObject.release() return timeStampdef getTodayTimeStamp(): global lockObject '''這個地方加個執行緒鎖,_strptime_time 執行緒不安全''' lockObject.acquire() now = datetime.datetime.now() timeStamp = '%s 00:00:00' % now.strftime( '%Y-%m-%d' ) timeStamp = time.strptime( timeStamp, '%Y-%m-%d %X' ) timeStamp = int(time.mktime( timeStamp )) lockObject.release() return timeStamp