There is a time module under Python with powerful functions. Today we will introduce the simple functions of this module:
- Import time
- Print time. Time ()
- Print time. localtime (Time. Time ())
- Print time. strftime ('% Y-% m-% d', time. localtime ())
- Print time. strftime ('% Y-% m-% d', time. localtime ())
- Print time. strftime ('% Y-% m-% d % H: % m: % s', time. localtime ())
- Print time. strftime ('% Y-% m-% d % I: % m: % s', time. localtime ())
- Print time. strftime ('% Y-% m-% d % H: % m: % s -- % A -- % C', time. localtime ())
- Print time. strftime ('% Y-% m-% d % H: % m: % s -- % x -- % x', time. localtime ())
Copy code
The following figure shows the effect:
- 1298953244.19
- Time. struct_time (tm_year = 2011, tm_mon = 3, tm_mday = 1, tm_hour = 12, tm_min = 20,
Tm_sec = 44, tm_wday = 1, tm_yday = 60, tm_isdst = 0)
- 2011-03-01
- 11-03-01
- 12:20:44
- 12:20:44
- 12:20:44 -- Tuesday -- 03/01/11 12:20:44
- 12:20:44 -- 03/01/11--12: 20: 44
Copy code
Hey, the results are good. It is still very detailed. The following describes some parameters. You can take a look at them:
Time. strftime has many parameters that allow you to output what you want at will:
The parameters of time. strftime are as follows:
Strftime (Format [, tuple])-> string
Returns the specified struct_time (current time by default) according to the specified formatted string.
Time and date formatting symbols in Python:
% Y two-digit year (00-99)
% Y indicates the four-digit year (000-9999)
% M month (01-12)
One day in % d month (0-31)
% H hour in 24-hour format (0-23)
% I 12-hour (01-12)
% M minutes (00 = 59)
% S seconds (00-59)
% A local simplified week name
% A local full week name
% B local simplified month name
% B local full month name
% C local Date and Time
% J one day in the year (001-366)
% P local equivalent of a. m. or P. M.
% U number of weeks in a year (00-53) Sunday is the start of the week
% W Week (0-6), Sunday is the beginning of the week
% W number of weeks in a year (00-53) Monday is the start of the week
% X local date Representation
% X Local Time Representation
% Z Current Time Zone name
% Itself