python獲取當前時間

2022-08-31 01:51:07 字數 427 閱讀 3695

首先我們得在前面獲取當前的時間戳,運用import time 取得當前的時間。然後運用時間函式列印出來就是

# 取得當前時間戳

import time

print time.time()

# 格式化時間戳為標準格式

print time.strftime('%y.%m.%d',time.localtime(time.time()))

# 獲取30天前的時間(通過加減秒數來獲取現在或者未來某個時間點)

print time.strftime('%y.%m.%d',time.localtime(time.time()-2592000))

這是當前列印時間的截圖

python 獲取當前時間

取得時間相關的資訊的話,要用到python time模組,python time模組裡面有很多非常好用的功能,你可以去官方 文件了解下,要取的當前時間的話,要取得當前時間的時間戳,時間戳好像是1970年到現在時間相隔的時間。你可以試下下面的方式來取得當前時間的時間戳 import time prin...

python 獲取當前時間

取得時間相關的資訊的話,要用到python time模組,python time模組裡面有很多非常好用的功能,你可以去官方 文件了解下,要取的當前時間的話,要取得當前時間的時間戳,時間戳好像是1970年到現在時間相隔的時間。以下面的方式來取得當前時間的時間戳 import time print ti...

Python 獲取當前時間

import time nowtime time.localtime 獲取當前時間 print time.strftime y m d h m s nowtime 對當前時間進行格式化並輸出 y年 四位數 000 9999 2020 y年 兩位數 00 99 2020 20 m月 01 12 d日 ...