程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

6、 Python learning notes - module -time module

編輯:Python
# time modular
"""
1、 Time related function modules
"""

# Introduce modules
import time
import datetime
# Print help documents
print(help(time))
# Time stamp , Returns the timestamp of the current time (1970 Floating point seconds after the era )
print(time.time())
# Expressed in scientific notation cpu Operation time
print(time.clock())
# Structured time , Print Greenwich mean time (UTC), return time.struct_time Object of type ( Tuple format ),(struct_time Is in time Object defined in the module to represent time ).
# tm_wday It means the day of the week , Monday is 0.tm_yday It means the day of the year .
print(time.gmtime())
# Structured time , Print local time .
print(time.localtime())
# String time , Custom format . Print month, year and day separately
"""
%Y Year with century as a decimal number.
%m Month as a decimal number [01,12].
%d Day of the month as a decimal number [01,31].
%H Hour (24-hour clock) as a decimal number [00,23].
%M Minute as a decimal number [00,59].
%S Second as a decimal number [00,61].
%z Time zone offset from UTC.
%a Locale's abbreviated weekday name.
%A Locale's full weekday name.
%b Locale's abbreviated month name.
%B Locale's full month name.
%c Locale's appropriate date and time representation.
%I Hour (12-hour clock) as a decimal number [01,12].
%p Locale's equivalent of either AM or PM.
"""
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
# String time to structured time
# adopt time.strptime Intercept some information
t = time.strptime('2018-04-20 15:30:25', '%Y-%m-%d %H:%M:%S')
print(t)
print(t.tm_wday)
# By default, the current time is printed as a string . Format has been defined and cannot be changed .
# Add timestamp parameter ( second ), Print the string time corresponding to the timestamp .
print(time.ctime())
print(time.ctime(2))
# Convert structured time to timestamps .
print(time.mktime(time.localtime()))
# Print the current time as a string
print(datetime.datetime.now())

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved