1. 程式人生 > >自動化學習第二週--python--日期和時間

自動化學習第二週--python--日期和時間

1.Python 提供了一個 time 和 calendar 模組可以用於格式化日期和時間。

2.格式化日期、時間

(1)python中時間日期格式化符號:

%y 兩位數的年份表示(00-99)
%Y 四位數的年份表示(000-9999)
%m 月份(01-12)
%d 月內中的一天(0-31)
%H 24小時制小時數(0-23)
%I 12小時制小時數(01-12)
%M 分鐘數(00=59)
%S 秒(00-59)

(2)格式化時間

   import time; # 引入time模組

# 格式化成2018-03-20 11:45:39形式

print (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

(3)當前時間戳

time.time()