DateTime Module Official Tutorial

Source: Internet
Author: User
Tags time zones timezones

8.1 Datetime-basic Date and time types

DateTime-Basic Date-time type

Source code:lib/datetime.py

Source: lib/datetime.py

The DateTime module supplies classes for manipulating dates and times in both simple and complex ways. While date and time arithmetic are supported,the focus of the implementation is on efficient attribute extraction for OUTPU t formatting and manipulation. For related Functionality,see also the time and calendar modules.

The DateTime module provides classes for both simple and complex operation dates and times. When the date and time support operations, the focus of the implementation (focus) is on the extraction and operation of valid attributes. You can also look at the time module and the Calendar module for a datetime-related module.

There is kinds of date and timeobjects: "Naive" and "aware"

There are two types of date and time objects: naive and aware

An aware object has sufficient knowledge of applicable algorithmic and political time Adjustments,such as time zone and DA Ylight Saving time Information,to locate itself relative to other aware objects. An aware object was used to represent a specific moment in time so is not open to interpretation.

Occupy position

A naive object does not contain enough information to unambiguously locate itself relative to other Date/time objects. Whether a Naive object represents coordinated Universal time (UTC), local time,or time in some other timezone was purely up t o The program,just like it's up to the program whether a particular number represents metres,miles,or mass. Naive objects is easy-to-understand and to work with,at the cost of ignoring some aspects of reality.

A naive object cannot hold enough information to clearly position itself relative to other date/time objects. Whether a naive object represents the time in UTC, local time, or other time zones is entirely up to the program, just as the naive object is determined by the program to determine whether a particular number represents meters, miles, or masses. Naive objects are easy to understand and easy to use when ignoring certain real aspects

For applications requiring aware objects,datetime and time objects has an optional time zone information Attribute,tzi Nfo,that can is set to an instance of a subclass of abstract Tzinfo class. These Tzinfo objects capture information about the offset from UTC time,the time zone Name,and whether daylight saving Tim E is in effect. Note that only one concrete tzinfo class,the timezone Class,is supplied by the datetime module. The TimeZone class can represent simple timezones with fixed offset from Utc,such as UTC itself or North American EST and EDT timezones. Supporting timezones at deeper levels of detail are up to the application. The rules for time adjustment across the world was more political than rational,change Frequently,and there was no standard Suitable for every application aside from UTC.

For applications that require aware objects, datetime and time objects have an optional time zone information property tzinfo, which can be set as an instance of an abstract Tzinfo class subclass that captures the offset of the UTC time, the time zone name, and whether the summer time system is valid information. It is important to note that only a specific Tzinfo class (TimeZone Class) is supported by the DateTime module. The TimeZone class can represent simple time zones with a fixed offset from UTC time, such as the UTC self Time zone, the North American Eastern Standard Time time zone (EST), and the Eastern Daylight Time zone (DST). In the deeper time zone support details are applied to control. Time adjustment rules around the world are more political than rationality (or interpreted as rationality), and time zone rules are changed in a frequency-sensitive way, except for UTC time Zones, where no standard is appropriate for every application.

The DateTime module export the following constants:

The time period module outputs the following constants:

Datetime. Minyear

Minimum-year constant variable in a DateTime class (Minyear)

The smallest year number allowed in a date or DateTime object. Minyear is 1.

The minimum number of years allowed in a date or DateTime object. The Minyear constant is 1.

Datetime. Maxyear

The largest year number allowed in a date or DateTime object. Maxyear is 9999.

The maximum number of years allowed in a date or DateTime object. Maxyear is 9999.

----------------------------------------------------------------------------------

See also:

You can also check

Module Calendar

Calendar Module

General Calendar related funtions.

General calendar-related functions

Module time

Time Module

Time Access and conversions.

Use and conversion of time

-------------------------------------------------------------------------------------

8.1.1 Available Types

Valid (available) types

Class Datetime.date

Date class in a datetime module

An idealized naive date,assuming the current Gregorian calendar always was,and always would be,in effect. Attributes:year,month and Day.

An idealized naive date, assuming that it is currently at Greenwich Mean time, is actually always going to be. Properties: Year, month and day

Class Datetime.time

Time class in a datetime module

An idealized time,independent of any particular day,assuming this every day have exactly 24*60*60 seconds (there is no Noti On the "Leap seconds" here).

An idealized time, independent of any particular day, assuming that every day has accurate 24*60*60 seconds (there is no "leap second" concept)

Attributes:hour,minute,second,microsecond,and Tzinfo.

Properties: Hours, minutes, seconds, microseconds, Tzinfo.

Class Datetime.datetime

DateTime class in DateTime module

A combination of a date and a time. Attributes:year,month,day,hour,minute,second,microsecond,and Tzinfo.

Combination of date and time. Attributes: Year, month, day, time, minute, second, microsecond, Tzinfo.

Class Datetime.timedelta

Time interval class in a datetime module

A duration Expressing the difference between the Date,time,or datetime instances to microsecond resolution.

Use a microsecond interval to express the differences between two date, time, or date and time instances

Class Datetime.tzinfo

The Tzinfo class in the date-time module

An abstract base class for time zone information objects. These is used by the DateTime and time classes to provide a customizable notion of time adjustment (for Example,to account For time zone and/or daylight saving time).

An abstract base class for the time zone information object. These are used by datetime classes and time classes to provide a customizable concept of time adjustment (for example, to interpret time zones and/or daylight saving times)

Class Datetime.timezone

Time zone class in a datetime module

A class that implements the Tzinfo abstract base class as a fixed offset from the UTC.

A class that implements the Tzinfo abstract base class as a fixed offset from the UTC time Zone

Tzinfo and timezone explain not very clearly, they do not understand

New in version 3.2.

New in version 3.2

Objects of these types is immutable.

These types of objects are immutable

Objects of the date type is always naive.

Objects of the date type are always naive.

An object of type Time or datetime could be naive or aware. A DateTime Object D is aware if d.tzinfo are not None and D.tzinfo.utcoffset (d) does not return None.if D.tzinfo are none,or If D.tzinfo is not None and D.tzinfo.utcoffset (d) returns None,d is naive. A Time Object T is aware if t.tzinfo are not None and T.tzinfo.utcoffset (None) does not return none.otherwise,t is naive.

DateTime Module Official Tutorial

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.