Python時間asctime()方法

Python時間asctime()方法將表示由gmtime()localtime()返回的時間的元組或struct_time轉換為以下形式:“Tue Feb 27 22:21:15 2019”的24個字元的字串。

語法

以下是asctime()方法的語法 -

time.asctime()

參數

  • t - 這是一個9個元素或struct_time的元組,表示由gmtime()localtime()函數返回的時間。

返回值

  • 此方法返回以下形式的24個字元的字串 - “Tue Feb 27 22:21:15 2019”。

示例

以下示例顯示了asctime()方法的用法 -

#!/usr/bin/python3
import time

t = time.localtime()
print ("asctime : ",time.asctime(t))

當運行上述程式時,它會產生以下結果 -

asctime :  Wed Jun 21 02:58:53 2019

上一篇: Python日期和時間 下一篇: Python函數