python datetime模塊來獲取當前的日期和時間


 

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import datetime
i = datetime.datetime.now()
print ("當前的日期和時間是 %s" % i)
print ("ISO格式的日期和時間是 %s" % i.isoformat())
print ("當前的年份是 %s" %i.year)
print ("當前的月份是 %s" %i.month)
print ("當前的日期是  %s" %i.day)
print ("dd/mm/yyyy 格式是  %s/%s/%s" % (i.day, i.month, i.year))
print ("當前小時是 %s" %i.hour)
print ("當前分鍾是 %s" %i.minute)
print ("當前秒是  %s" %i.second)

輸出

當前的日期和時間是 2019-01-04 11:04:24.874607
ISO格式的日期和時間是 2019-01-04T11:04:24.874607
當前的年份是 2019
當前的月份是 1
當前的日期是  4
dd/mm/yyyy 格式是  4/1/2019
當前小時是 11
當前分鍾是 4
當前秒是  24

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM