python之獲取當前時間

2021-10-04 14:16:19 字數 676 閱讀 9888

本文使用的python版本是3.8.1

2.32位

macos 指令

意義%y

十進位制數表示的帶世紀的年份(eg:2020)

%y十進位制數 [00,99] 表示的沒有世紀的年份(eg:20)

%m十進位制數 [01,12] 表示的月

%d十進位制數 [01,31] 表示的哪一天

%h十進位制數 [00,23] 表示的小時(24小時制)

%i十進位制數 [01,12] 表示的小時(12小時制)

%m十進位制數 [00,59] 表示的分鐘

%s十進位制數 [00,61] 表示的秒

from time import localtime,strftime

time = strftime("%y年%m月%d日 %a %i:%m:%s",localtime())

print(time)#輸出結果:2023年03月31日 tuesday 10:05:03

from datetime import datetime

dt = datetime.now()

#兩種列印時間的方式

print(f"今天是:年月日 ::")

print(dt.strftime('今天是:%y年%m月%d日 %h:%m:%s'))

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日 ...