Python Module-datetime module

Source: Internet
Author: User
Tags timedelta

Tag: Day does not have a post BSP return between the specified GPO timestamp

Datetime.datetime.now () returns the current datetime date type

>>> D=datetime.datetime.now () >>> ddatetime.datetime (2018, 2, +, +, A, A, 372222) >>> D.year2018>>> d.month2>>> d.timetuple () time.struct_time (tm_year=2018, tm_mon=2, tm_mday=17, tm_ Hour=17, tm_min=41, tm_sec=49, tm_wday=5, tm_yday=48, Tm_isdst=-1) >>> D.timestamp () #转换为时间戳1518860509.372222 >>> d.replace (year=1997,month=9,day=21) #时间替换datetime. DateTime (1997, 9, 21, 17, 41, 49, 372222)

Datetime.date.fromtimestamp () converts a timestamp to a datetime date type

>>> Datetime.date.fromtimestamp (1518860509.372222) datetime.date (2018, 2, 17)

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

>>> Datetime.datetime.now () datetime.datetime (2018, 2, +, +, A, 336825) >>> Datetime.datetime.now ()-Datetime.timedelta (3) #如果没有指定, default is 3 days datetime.datetime (2018, 2, +, +, +, 980665) >> > Datetime.datetime.now ()-Datetime.timedelta (days=3) #减去3天datetime. DateTime (2018, 2, 9, 23454) >>& Gt Datetime.datetime.now () + Datetime.timedelta (hours=3) #加3个小时datetime. DateTime (2018, 2, 17, 20, 50, 19, 688480

Python Module-datetime 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.