Time.time () gets the current timestamp
For example:
#!/usr/bin/-*-coding:utf-8-*-import time ; ="Current timestamp is:", ticks
Results:
The current timestamp is: 1491750320.74
Time tuple
For example, get the current time:
# !/usr/bin/python # -*-coding:utf-8-*- Import = time.localtime (time.time ())print" local time:", localtime
Get the formatted time
LocalTime = Time . Asctime(Time.localtime (Time.time ()))print" local time:", LocalTime
Results:
local time: Sun APR 09 23:12:15 2017
Formatted date
Format is a bit like Java date formatting
Import Time#formatted as 2016-03-20 11:45:39 in the form ofPrintTime.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ())#formatted as Sat 28 22:24:24 2016 FormPrintTime.strftime ("%a%b%d%h:%m:%s%Y", Time.localtime ())#convert a format string to a timestampA ="Sat Mar 22:24:24"PrintTime.mktime (Time.strptime (A,"%a%b%d%h:%m:%s%Y"))
Results:
2017-04-09 23:13:50Sun Apr 09 23:13:50 20171459175064.0
Date formatting symbols
Get a calendar for a month
Display information for a month directly in the form of a calendar
Calendar for April 2017:
#!/usr/bin/python
#-*-Coding:utf-8-*-
Import Calendar
Calendar.month (2017, 4)
Print "The following output April 2017 calendar:"
Print Cal;
Show Results:
The following outputs the April 2017 calendar:
April 2017
Mo Tu We Th Fr Sa Su
0 S
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Time Module
Calendar Module
Python Date and time