For example, print ','. join (datelist)
You can combine all the items in the datelist list into a string. Of course, this expression inserts a comma in the middle of each project. This method is more concise than the loop method.
Date operations must use the time or datetime Library
Import time
>>> S = "2006-1-2"
>>> Time. strptime (s, "% Y-% m-% d)
This is to convert the date and time in string format into a date object.
The meanings of escape characters are as follows:
% 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
One day in % d month (0-31)
% H hour in 24-hour format (0-23)
% I 12-hour (01-12)
% J one day in the year (001-366)
% M month (01-12)
% M minutes (00 = 59)
% P local equivalent of A. M. or P. M.
% S seconds (00-59)
% 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
% Y two-digit year (00-99)
% Y indicates the four-digit year (000-9999)
% Z Current Time Zone name
% Itself
========================================================== ====
#-*-Coding: UTF-8 -*-
Import time
Import datetime
#2007-11-25 15:36:35
# Using the datetime module can easily solve this problem, for example:
D1 = datetime. datetime (2005, 2, 16)
D2 = datetime. datetime (2004, 12, 31)
# Result: 47
Print (d1-d2). days
# The preceding example shows how to calculate the number of days for two different dates.
Starttime = datetime. datetime. now ()
Endtime = datetime. datetime. now ()
Print (endtime-starttime). seconds
# The previous example demonstrates the example of calculating the running time, which is displayed in seconds.
D1 = datetime. datetime. now ()
D3 = d1 + datetime. timedelta (days = 10)
Print str (d3)
Print d3.ctime ()
# The previous example shows the 10 days after calculating the current time.
# Replace hour days with hours
# The common classes in this document are datetime and timedelta. They can be added or subtracted from each other.
# Each class has some methods and attributes to view specific values, such as datetime: day, hour, and weekday;
# Timedelta can be viewed in days and seconds.
#
# Time, datetime, and string Conversions
#
# String-> time
# Time. strptime (publishDate, "% Y-% m-% d % H: % M: % S ")
#
# Time-> string
# Time. strftime ("% y-% m-% d", t)
Date = '2014-01-01'
Print type (date)
Date = time. strptime (date, "% Y-% m-% d ")
Print type (date)
Print date [0]
D4 = datetime. datetime (date [0], date [1], date [2])
Print d4
Print type (d4)
# Convert a date and time object to a string.
Date = time. strftime ("% y-% m-% d", date)
Print type (date)
# Where d is a date and time object