datetime Processing of Python

Source: Internet
Author: User
Tags timedelta

Python version 3.5

1.datetime Package Import method

There are two ways to import a DateTime package ( new Note ):

The first type: import datetime # Importing Time date

>>> get current time: now = Datetime.datetime.now ()-------2017-09-15 11:29:21.796463

>>> get today's date: day = Datetime.date.today ()---------2017-09-15

>>> get yesterday's date: Yesterday = Today-datetime.timedelta (Days=1)---------2017-09-14

>>> get tomorrow's date: Tom = Today + Datetime.timedelta (Days=1)---------2017-09-16 (days is a parameter that represents today's date difference, can be changed, days=2, indicates the day after tomorrow 's date)

Datetime.strptime () Usage date string converted to date

>>>now = 2017-09-15 11:29:21.796463

>>>now.strptime ('%y-%m-%d ')---------2017-09-15

>>>now.strptime ('%y-%m-%d%h:%m:%s ')---------2017-09-15 11:29:21

Second type: from datetime import datetime

>>> get current time: now = DateTime.Now ()-------2017-09-15 11:29:21.796463 (Import a datetime module in a datetime package that can be called directly)

>>> get today's date: now = Datetime.today ()---------2017-09-15 11:29:21.796463 (Note: And today = Datetime.date.today () No As

datetime Processing of Python

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.