




執行結果:

配合格式化字串:

輸出結果:
get_time_str()
Out[592]: ‘20230425_115909’
推薦hahow線上學習python: https://igrape.net/30afN
結合前綴f的格式化字串:

time模組本身也有
time.strftime?
#string format time

strftime 函數在 Python 中用於將時間元組(tuple)轉換為特定格式的字符串。當時間元組未提供時,它會使用由 localtime() 返回的當前時間。該函數支持多種格式代碼,用於表示年、月、日、時、分、秒等。
以下是一些常用的格式代碼及其含義:
%Y:帶世紀的年份(例如 2023)。%m:月份(01 至 12)。%d:月份中的天數(01 至 31)。%H:24小時制的小時數(00 至 23)。%M:分鐘數(00 至 59)。%S:秒數(00 至 61)。%z:UTC的時區偏移。%a:當地語言環境的縮寫星期名稱。%A:當地語言環境的完整星期名稱。%b:當地語言環境的縮寫月份名稱。%B:當地語言環境的完整月份名稱。%c:當地語言環境適當的日期和時間表示。%I:12小時制的小時數(01 至 12)。%p:當地語言環境的上午或下午標記(AM 或 PM)。
%m: 月份
%M: 分鐘數
#區分大小寫
%Y: 2023
%y: 23

strftime可以取代自己寫的get_time_str()

time.mktime()

從timestamp轉為localtime:

推薦hahow線上學習python: https://igrape.net/30afN








![Python 讀取 DOCX 圖片關聯:qn+find/findall 與 XPath 的實戰對照 from lxml import etree ; from docx.oxml.ns import qn; lxml.etree._Element.findall( f”.//{ qn(‘a:blip’) }” ) ; .get( qn(“r:embed”) ) #獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’) ; lxml.etree._Element.xpath( “//a:blip/@r:embed”, namespaces = NS) #/@r:embed = 獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’),使用.findall() 要先.findall()獲取List[_Element],再迴圈_Element.get()獲取屬性值, .xpath() 第一個參數path 使用”//a:blip/@r:embed” ,可直接獲取屬性值(List[str]如: [‘rId4’, ‘rId5’]) ; 如何對docx真實移除圖片瘦身? Python 讀取 DOCX 圖片關聯:qn+find/findall 與 XPath 的實戰對照 from lxml import etree ; from docx.oxml.ns import qn; lxml.etree._Element.findall( f”.//{ qn(‘a:blip’) }” ) ; .get( qn(“r:embed”) ) #獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’) ; lxml.etree._Element.xpath( “//a:blip/@r:embed”, namespaces = NS) #/@r:embed = 獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’),使用.findall() 要先.findall()獲取List[_Element],再迴圈_Element.get()獲取屬性值, .xpath() 第一個參數path 使用”//a:blip/@r:embed” ,可直接獲取屬性值(List[str]如: [‘rId4’, ‘rId5’]) ; 如何對docx真實移除圖片瘦身?](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2025/11/20251119130848_0_3fbf6b.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

近期留言