Python Basics-Day 5 learning note-Standard library of modules: DateTime (2)

Source: Internet
Author: User
Tags time zones

Introduced

The Datetime module is the re-encapsulation of the time module, providing more interfaces. The main is the date and time of parsing, formatting and operation.

Other time-related modules:

Time-basic

Calendar-basic

Pytz-About time zones

Dateutil-extension of datetime

Common Operation Times Class
ImportDatetimet= Datetime.time (+/-)#01:02:03Print(t)#syntax: Datetime.time (HOUR,MIN,SEC)Print("Hour:", T.hour)#hour:1Print('minute:', T.minute)#Minute:2Print('Second:', T.second)Print('microsecond:', T.microsecond)Print('Tzinfo:', T.tzinfo)#Time Zone InfoPrint('earlist:', Datetime.time.min)#earlist:00:00:00Print('Latest:', Datetime.time.max)#latest:23:59:59.999999Print('Resolution:', datetime.time.resolution)#resolution:0:00:00.000001

Note that microsecond milliseconds cannot be expressed in float mode, only integers.

Dates class

The date class is primarily used to represent calendar date. The attributes include year, month, and day.

ImportDatetimetoday=Datetime.date.today ()Print(today)#2017-08-20Print('CTime:', Today.ctime ())#Ctime:sun 00:00:00Print('ordinal:', Today.toordinal ())#ordinal:736561Print("Year :", Today.year)#year:2017Print('Month:', Today.month)#Month:8Print('Day :', Today.day)#day:20Tuple_today=today.timetuple ()Print(Tuple_today)#time.struct_time (tm_year=2017, tm_mon=8, tm_mday=20, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=232, tm_ Isdst=-1)Print(tuple_today.tm_year)#extract the elements in the Struct_time

Timedeltas

Date arithmetic

Comparing values

Combining dates and times

Formatting and parsing

Time zones

Python Basics-Day 5 learning note-Standard library of modules: DateTime (2)

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.