Python datetimeを利用してUNIX時間を取得する

環境
Python 3.9.13
Windows 10 Home 64bit
PyCharm 2022.2.1 (Community Edition)

構文
import datetime
ライブラリ「datetime」をimportして
UNIX時間を取得します

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import datetime
dt = datetime.datetime.now()
res = dt.timestamp()
print(res)
import datetime dt = datetime.datetime.now() res = dt.timestamp() print(res)
import datetime

dt = datetime.datetime.now()
res = dt.timestamp()

print(res)

実行結果
1676560092.522346

Python

Posted by arkgame