Advanced Nineth class datetime of the Python module

Source: Internet
Author: User
Tags month name string format timedelta

A datetime module is a collection of date and time two modules. There are 2 constants in the DateTime module: Maxyear has a value of 9999,minyear of 1.

The DateTime module defines 5 classes, each of which is

Datetime.date: A class that represents a date.

The date class has three parameters, Datetime.date (year,month,day), and returns Year-month-day

Method:

1.datetime.date.ctime (), return format as Sun APR 16 00:00:00 2017

2.datetime.date.fromtimestamp (timestamp), returns a Date object based on a given time timestamp, Datetime.date.today () has the same effect

3.datetime.date.isocalendar (): Returns a tuple of the format (Year,month,day), (2017, 15, 6)

4.datetime.date.isoformat (): Returns a format such as Yyyy-mm-dd

5.datetime.date.isoweekday (): Returns the week of the given date (0-6), Monday = 0, Sunday =6

6.datetime.date.replace (Year,month,day): replaces the given date but does not change the original date

7.datetime.date.strftime (format): Formats the DateTime according to the given format.

8.datetime.date.timetuple (): Returns the Time.struct_time object corresponding to the date

Time.struct_time (tm_year=2017, tm_mon=4, tm_mday=15, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=105, tm_isdst=- 1)

9.datetime.date.weekday (): Return day of the week

Python format symbols in time Date:

%y Two-digit year representation (00-99)

%Y Four-digit year representation (000-9999)

%m Month (01-12)

One day in%d months (0-31)

%H 24-hour hours (0-23)

%I 12-hour hours (01-12)

%M minutes (00=59)

%s seconds (00-59)

%a Local Simplified Week name

%A Local Full week name

%b a locally simplified month name

%B Local Full month name

%c Local corresponding date representation and time representation

%j Day of the Year (001-366)

%p the equivalent of a local a.m. or p.m.

%u weeks of the year (00-53) Sunday is the beginning of the week

%w Week (0-6), Sunday for the beginning of the week

%W Week of the Year (00-53) Monday is the beginning of the week

%x Local corresponding date representation

%x Local corresponding time representation

%Z the name of the current time zone

Percent% of the number itself

Second, Datetime.datetime: The class that represents the date time.

The DateTime class has a number of parameters, DateTime (year, month, day[, hour[, minute[, second[, Microsecond[,tzinfo]]), and returns date, time, and seconds

Datetime.datetime.ctime ()

Datetime.datetime.now (). Date (): Returns the day part of the current datetime

Datetime.datetime.now (). Time (): Returns the part of the current date time

Datetime.datetime.fromtimestamp ()

Datetime.datetime.now (): Returns the current system time

Datetime.datetime.replace ()

Datetime.datetime.strftime (): Converted from date format to string format

Datetime.datetime.now (). Strftime ('%b-%d-%y%h:%m:%s ')
' apr-16-2017 21:01:35 '

Datetime.datetime.strptime (): converted from string format to date format

Datetime.time: A class that represents time.

The time class has 5 parameters, Datetime.time (hour,minute,second,microsecond,tzoninfo), and returns 08:29:30

1.datetime.time.replace ()

2.datetime.time.strftime (format): Returns time in format

3.datetime.time.tzname (): Returns the time zone name

4.datetime.time.utcoffset (): Time offset for return time zone

Datetime.timedelta: Represents a time interval, that is, the interval of two points in time.

The Datetime.datetime.timedelta is used to calculate the difference between two dates, for example:

>>> a=datetime.datetime.now ()>>> b=datetime.datetime.now ()>>>  Adatetime.datetime (4, 2017, 16, 4, 871000)>>> bdatetime.datetime, (603000)>>> b-8, 732000)>>> (b-a). Seconds8

V. Datetime.tzinfo: Information about the time zone.

Advanced Nineth class datetime of the Python module

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.