python-get the day before the current time (or one second)

Source: Internet
Author: User
Tags local time timedelta

Get the day before the current time (or one second)


If the current time is: 2014-6-11 17:12:45
Day before: 2014-6-10 17:12:45
Previous second: 2014-6-11 17:12:44

 #coding =utf-8  import timeimport Datetimeprint time.ctime () //Print current time  now_time  = Datetime.datetime.now () //returns the current time of the local time zone  print now_timeyesterday  = Now_ Time + datetime . timedelta (days =-1   )  //yesterday's now  print yesterdaynow_old  = Now_time + datetime . timedelta (seconds =-1   )  //now the previous second  print now_old  

Operation Result:
Wed June 11 17:21:07 2014
2014-06-11 17:21:07.750000
2014-06-10 17:21:07.750000
2014-06-11 17:21:06.750000


python-get the day before the current time (or one second)

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.