How to use the DateTime module in Python

Source: Internet
Author: User

The following record of the DateTime module Some of the methods used, first print out the current time, and then print out before and after 3 days, after 3 hours, after 3 minutes, after 3 seconds of expression, below look at the code:

Import datetime Now    
= Datetime.datetime.now ()    
print now    
#往后3小时, 2 days, 3 minutes, 3 seconds    
Print Datetime.datetime.now () + Datetime.timedelta (hours=3)    
print datetime.datetime.now () + Datetime.timedelta (days=3 )    
print Datetime.datetime.now () + Datetime.timedelta (minutes=3)    
print datetime.datetime.now () + Datetime.timedelta (seconds=3)

Here's how it works:

2011-03-04 14:07:18.437000
2011-03-07 14:07:18.437000
2011-03-04 17:07:18.437000
2011-03-04 14:10:18.437000
2011-03-04 14:07:21.437000

This article from "You are a passer-by or fearless" blog, please be sure to keep this source http://world77.blog.51cto.com/414605/506415

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.