Python3-time-asctime

提供:Dev Guides
移動先:案内検索

Python 3-time asctime()メソッド

説明

メソッド* asctime()*は、gmtime()またはlocaltime()によって返される時刻を表すタプルまたはstruct_timeを、次の形式の24文字の文字列に変換します-'Tue Feb 17 23:21:05 2009'。

構文

以下は* asctime()*メソッドの構文です-

time.asctime([t]))

パラメーター

*t* -これは、gmtime()またはlocaltime()関数によって返される時刻を表す9つの要素またはstruct_timeのタプルです。

戻り値

このメソッドは、「Tue Feb 17 23:21:05 2009」という形式の24文字の文字列を返します。

次の例は、asctime()メソッドの使用法を示しています。

#!/usr/bin/python3
import time

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

結果

上記のプログラムを実行すると、次の結果が生成されます-

asctime :  Mon Feb 15 09:46:24 2016