Obtain the current time and output it using a string.
Format: % Y-% m-% d % H: % M: % s'
Datetime. datetime. now (). strftime ('% Y-% m-% d % H: % M: % s ')
Obtains the current time, but only retains the date.
Datetime. datetime. now (). date ()
Convert string to datetime type
Input string format: '% Y-% m-% d'
Datetime. datetime. strptime (time, '% Y-% m-% D ')
Print 'start at: ', datetime. datetime. now (). strftime (' % Y-% m-% d % H: % M: % S. % F ')
Print 'start at: ', time. strftime ('% Y-% m-% d % H: % M: % S. % F', time. localtime (time. time ()))
Appendix:
Formatted symbol Summary
% A: Weekday name, abbr.
% A full name of the day of the week
Abbreviated Month name, abbr.
% B full name of Month name
% C standard date string Complete date and time representation
% D Day of the month in decimal format
% H Hour in the 24-hour format (24-Hour clock)
% I Hour hour in 12-Hour format (12-hour clock)
% J Day of the year in decimal format
Month number in % m decimal format
% M decimal representation of minutes Minute number
% S decimal Second number
% U indicates the Week of the year. Sunday is regarded as the first day (value ranges from 0 to 53) Week number (Sunday first weekday)
% W decimal indicates the day of the week (the value ranges from 0 to 6, and Sunday is 0) weekday number
% W indicates the Week of the year. Monday is regarded as the first day (from 0 to 53) Week number (Monday first weekday)
% X standard date string Complete date representation (e.g. 13/01/08)
% X standard time string Complete time representation (e.g. 17:02:10)
% Y decimal Year without century (value ranges from 0 to 99) Year number within century
% Y indicates the tenth Year number of the century section.
% Z, % Z Time Zone name. If the time zone name cannot be obtained, an empty character is returned. Name of time zone
% Percent sign