Dates and Times

简介: Dates and Times

Dates and Times
Dates

Calendar date values are represented with the date class. Instances have attributes for year, month, and day. It is easy to create a date representing the current date using the today()

The following is example code:

import datetime

today = datetime.date.today()

print('Today is {}'.format(today))


print('ctime :', today.ctime())

tt = today.timetuple()
print('tuple     : tm_year =', tt.tm_year)
print('          : tm_mon  =', tt.tm_mon)
print('          : tm_mday =', tt.tm_mday)
print('          : tm_hour =', tt.tm_hour)
print('          : tm_min  =', tt.tm_min)
print('          : tm_sec  =', tt.tm_sec)
print('          : tm_wday =', tt.tm_wday)
print('          : tm_yday =', tt.tm_yday)
print('          : tm_isdst=', tt.tm_isdst)

print('ordinal:', today.toordinal())
print('Year   :', today.year)
print('Mon    :', today.month)
print('Day    :', today.day)

This example prints the current date in several formats.

D:\Python39\python.exe D:/My_Project/date_time_demo.py
Today is 2023-04-11
ctime : Tue Apr 11 00:00:00 2023
tuple     : tm_year = 2023
          : tm_mon  = 4
          : tm_mday = 11
          : tm_hour = 0
          : tm_min  = 0
          : tm_sec  = 0
          : tm_wday = 1
          : tm_yday = 101
          : tm_isdst= -1
ordinal: 738621
Year   : 2023
Mon    : 4
Day    : 11

Process finished with exit code 0

When I see the program’s result, I suddenly find that one hundred days have already passed. Where have the time gone? So, Please don’t waste time.

相关文章
|
人工智能 算法
1305:Maximum sum
1305:Maximum sum
HDOJ1003Max Sum
HDOJ1003Max Sum
81 0
1104. Sum of Number Segments (20) consecutive subsequence 每个数出现的次数
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence.
968 0
|
PyTorch 算法框架/工具
A trap of parameter ‘size_average’ in pytorch 详解
pytorch的入门教程中有这样的一句: 1 2 3 4 5 loss = torch.nn.
1775 0
Time range (447392) for take 'Take 001' is larger than maximum allowed(100000).
http://www.cnblogs.com/lopezycj/archive/2012/05/16/unity3d_tuchao.html   https://forum.unity3d.com/threads/time-range-447406-for-translation-curve-s-on-node-bone001-on-take-take-001-what-the.