I learned a little about Python's datetime module. This time only the date object.
From the official Python documentation
The datetime module provides classes for manipulating date and time data in both simple and complex ways. While four arithmetic operations on dates and times are supported, this module implementation focuses on efficient retrieval of attributes for output formatting and manipulation.
datetime.date(year, month, day)
All arguments are required. A date object with the date and time specified by the argument is created.
date.today()
Returns the current local date.
date.fromtimestamp(timestamp)
Returns the local date corresponding to the POSIX timestamp given in the argument. If the timestamp is outside the range of values supported by the platform C function localtime (), it may throw an OverflowError. If the call to localtime () fails, OSError may be thrown.
date.replace(year, month, day)
Returns a data object with the parameters specified by the keyword arguments replaced.
date.weekday()
Returns the day of the week as an integer, with Monday as 0 and Sunday as 6.
date.isoweekday()
Returns an integer with Monday as 1 and Sunday as 7.
date.strftime(format)
Returns a character string that represents the date according to the format character string specified by format.
>>> import datetime
datetime.date (2000, 1, 1) # Create a date object that represents January 1, 2000 datetime.date(2000, 1, 1)
datetime.date.today () # Create a date object that represents today's date datetime.date(2016, 5, 6)
d = datetime.date.today() d datetime.date(2016, 5, 6)
d.replace (year = 1990) # date Change the year of the object datetime.date(1990, 5, 6)
d.weekday () # Returns the day of the week as an integer (with Monday as 0) 4
d.isoweekday () # Returns the day of the week as an integer (with Monday as 1) 5
d.strftime ('% Y-% m-% d') # Display in the format given to the argument '2016-05-06'
Recommended Posts