Processing of time in Python-Date and Time

Source: Internet
Author: User
#  ! /Usr/bin/Python  
# Coding = UTF-8

From Datetime Import Datetime, date, time

"""
The date type, as its name implies, only represents the date, and time only represents the time
"""
Today = date. Today ()

Attrs = [
( " Year " , " Year " ),( ' Month ' , " Month " ),( ' Day ' , " Day " )
]
For K, V In Attrs:
" Today. % s = % s # % s " % (K, getattr (today, k), V)

# The day of the week. Same as datetime rules
Today. isoweekday ()
Today. weekday ()

# Returns a time structure. Of course, there is no time information.
Today. timetuple ()

# Modify. Same as datetime rules
Today. Replace (month = 1)

# It cannot be converted back to a string.
Today. strftime ( " % Y-% m-% d " )

Now = Time (12, 13, 14)
Attrs = [
( " Hour " ," Hours " ),( ' Minute ' , " Minute " ),( ' Second ' , " Seconds " ),( " Microsecond " , " Millisecond " )
]
For K, V In Attrs:
" Now. % s = % s # % s " % (K, getattr (now, k), V)

# Modify. Same as datetime rules
Now. Replace (minute = 1)
# It cannot be converted back to a string.
Now. strftime ( " % H: % m: % s " )

# Merge date and time into datetime
Print Datetime. Combine (today, now)
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.