利用Python內置函數獲取當前時間python
python version 3.4.3函數
module : timecode
代碼以下:utf-8
# -*- charset:utf-8 -*- import time #利用內置函數計算當前時間 currentTime = time.time() totalSeconds = int(currentTime) currentSecond = totalSeconds % 60 totalMinutes = totalSeconds // 60 currentMinute = totalMinutes % 60 totalHours = totalMinutes // 60 currentHour = totalHours % 24 #獲取的總秒數是以格林尼治時間爲標準的,北京在東8時區,因此求得的時間要+8小時 print("當前時間是:",(currentHour+8)," : ",currentMinute," : ",currentSecond)