To use a module, first import the module in
Import Time
Let's start by importing the module we need to use for this article.
Let's start with the time module, the function in the time module
--sleep: Hibernate specified number of seconds (can be decimal)
Import Time Print (" start ") time.sleep (5) Print (" end ")
#如果在pycharm中输入这段代码, from the beginning to the end of the middle will stay for 5 seconds, sleep after the parentheses filled with the number of seconds
--time: Get timestamp
Import= time.time ()print(t)# This code is to get the timestamp ( From 1970-01-01 00:00:00 to the number of seconds you entered the code runtime)
--localtime: Converting a timestamp to an object
Import time
Local_time =print(local_time)# prints out the time of day (s) Local_time.tm_year)# Specify the output corresponding year print(local_time[0])# You can also specify the subscript output year
Mktime: Convert to timestamp based on date and year
Import time
New_time = Time.mktime ((2099, 9, 9, 1, 212, 0))# The above brackets are filled with custom time, to write enough 9 numbers print< /c3>(new_time)# output of 1970-01-01 00:00:00 to custom time in seconds
Gmtime: function with localtime
Import time
GT = time.gmtime ()print(GT)# outputs the current time of year/month day seconds
Timezone:0 time zone to your time zone in seconds (/3600 = hours)
Import time
Print(time.timezone/3600)# I'm in the East 8 zone, so the output is -8.0 .
Strftime: Formatting Time.struct_time objects to display
Import time
Local_time =time.localtime ()#formatted displayPrint(Time.strftime ('%y-%m-%d%h:%m:%s', Local_time))#format of the specified outputPrint(Time.strftime ('%d', Local_time))#\d is a specific display format month/day/year#%Y: Year (4-bit),%Y: Year (2-bit),%m: Month,%d: day,%d: month/day/year,%H: when#%M: Minutes,%s: sec,%w: Week (1~7),%w: This week is the first week of this year#a specific display formatPrint(Time.asctime ())#format output Current time
Python--time (Time) module