Python (6) outputs the current time and pushes the date up to seven days ago

Source: Internet
Author: User

Project development needs: (including time functions) datetime

Requires the current date, and displays the timeline, and then launches the specific date seven days ago

1 #!/usr/bin/env python2 #-*-coding=utf-8-*-3 ImportRe4 Import Time5  fromDatetimeImportdatetime6now =DateTime.Now ()7List = [0,31,28,31,30,31,30,31,31,30,31,30,31]8 defJudge (year):#determine if a leap year9     ifYear% 100 = = 0 andYear% 400 = =0:Ten          return1 One     elifYear% 100! = 0 andYear% 4 = =0: A          return1 -     return0 -  the defgetnowtime (): -     #the current time -     Print "Now time :" -     Printtime.time () +     PrintTime.strftime ('%y-%m-%d%h:%m:%s', Time.localtime (Time.time ())) -     #output current: Month and day to undertake the above now = DateTime.Now () +     #y = now.year A     #m = Now.month at     #d = Now.day -     #Enter Month Date: -     Print "Input:" -y =Int (raw_input ()) -m =Int (raw_input ()) -D =Int (raw_input ()) in     #print time.time () -     #Output Month Date + specific time to     #y = now.year +     #m = Now.month -     #d = Now.day theYMD =judge (y) *     Print "Input Time:" $     PrintStr (y) +"-"+str (m) +"-"+Str (d)Panax Notoginseng     #if it is a leap year, then February will add a -LIST[2] = list[2] +Ymd the     #time backwards 7 days +     if(d>7): AD = d-7 the     Else: +         #if it is janurary -         ifM!=1: $m = m-1 $D = list[m]+d-7 -         #if it is janurary -         Else: they = y-1#year minus 1 -m = 12#Month to DecemberWuyiD = d+list[12]-7 the     #restore the original days of February -     Print "Eryue:"+STR (List [2]) WuLIST[2] = list[2]-Ymd -     #date of output seven days seven About     Print 'Seven days ago:' $     PrintStr (y) +"-"+str (m) +"-"+Str (d) - if __name__=="__main__": -Getnowtime ()

Code test:

D:\Python27\python.exe d:/py/bfun/donghua/test.pynow time:1456717147.792016-02-29 11:39:07

input:20150307input time:2015-3-7Seven days ago:2015-2-28

input:20160307Input time:2016-3-7eryue:29Seven days ago:2016-2-29


Input
2016
01
07
Input Time:
2016-1-7
Eryue:29
Seven days ago:
2015-12-31

Python (6) outputs the current time and pushes the date up to seven days ago

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.