This article describes how to convert strings and dates in python, and describes how to use time and datetime functions in Python, for more information about how to convert strings and dates in python, see the following example. Share it with you for your reference. The specific analysis is as follows:
The time and datetime functions are used here.
''' @ Author: jiangqh''' import time, datetime # date to strprint time. strftime ("% Y-% m-% d % X", time. localtime () # str to datet = time. strptime ("2009-08-08", "% Y-% m-% d") y, m, d = t [0: 3] print datetime. datetime (y, m, d)
Output result:
10: 43: 072009-08-08 00:00:00
Character:
% A short weekly
% A full English week
% B short for English month
% B full English month
% C display local Date and Time
% D date, 1-31
% H hour, 0-23
% I hour, 0-12
% M month, 01-12
% M minutes, 1-59
% J day of the year
% W indicates the day of the week
% W week
% X date of the current day
% X local day time
% Y year between and 99
Full spelling of % Y year
I hope this article will help you with Python programming.