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.

相关文章
成功解决but is 0 and 2 (computed from start 0 and end 9223372 over shape with rank 2 and stride-1)
成功解决but is 0 and 2 (computed from start 0 and end 9223372 over shape with rank 2 and stride-1)
|
人工智能 算法
1305:Maximum sum
1305:Maximum sum
|
文件存储
Sum of Round Numbers
Sum of Round Numbers
142 0
Sum of Round Numbers
Maximum Subsequence Sum
最大连续子列和问题,在此给出题解 (浙大PTA https://pintia.cn/problem-sets/16/problems/665)
|
人工智能
Rem of Sum is Num——UPC
题目描述 Given are a sequence of N positive integers A1,A2,…,AN, and a positive integer K. Find the number of non-empty contiguous subsequences in A such that the remainder when dividing the sum of its elements by K is equal to the number of its elements.
117 0
1104. Sum of Number Segments (20) consecutive subsequence 每个数出现的次数
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence.
973 0
|
人工智能 机器学习/深度学习
1007. Maximum Subsequence Sum (25)
简析:求最大子列和,并输出其首末元素。在线处理,关键在于求首末元素。 本题囧,16年9月做出来过,现在15分钟只能拿到22分,有一个测试点过不了。
980 0