#! /usr/bin/env python
#-*-Coding:utf-8-*-
From datetime import *
# The DateTime module defines the following classes:
# Datetime.date: A class that represents a date. The commonly used attributes are year, month and day;
# Datetime.time: A class that represents time. The commonly used properties are hour, minute, second, microsecond;
# Datetime.datetime: Represents the DateTime.
# Datetime.timedelta: Represents the time interval, which is the length between two points in time.
# Datetime.tzinfo: Related information about the time zone.
#1. Date represents a day that consists of a year, month, and date
t = date.today () #返回一个表示当前本地日期的date对象
Print (t)
Print (T.year,t.month,t.day) #年, month, day
T1 = T.replace (day=12) #date. Replace (year, month, day): Generates a new Date object, substituting the attributes in the original object with the specified years, months, and days of the parameter
Print (T1)
Print (T.timetuple ()) # returns the Time.struct_time object corresponding to the date
Print (T.toordinal ()) #返回日期对应的Gregorian Calendar Date
Print (T.weekday ()) #如果是星期一, returns 0 if it is Week 2, returns 1, and so on
T3 = t1-t #日期进行加减运算
Print (T3)
Print (T<T1) #日期比较
#2. Time, which is made up of hours, minutes, seconds, and microseconds
TM = Time (15,53,5) #构造一个time
Print (tm)
TM1 = Tm.replace (hour=13) #根据参数替换时, minutes, seconds to generate a new time
Print (TM1)
Print (Tm.hour,tm.minute,tm.second) # time, minutes, seconds
#3. DateTime class All information for date and time
td = Datetime.today () #当前本地时间的datetime对象
Print (TD)
Tu = Datetime.utcnow () #当前utc时间的datetime对象
Print (TU)
to = Datetime.combine (T,TM) #根据date和time, create a DateTime object
Print (To)
Python datetime module