How to get the time

Source: Internet
Author: User
>>> import time>>> now_time = time.localtime()>>> now_timetime.struct_time(tm_year=2014, tm_mon=6, tm_mday=28, tm_hour=21, tm_min=31, tm_sec=47, tm_wday=5, tm_yday=179, tm_isdst=0)>>> type(now_time)<type 'time.struct_time'>>>> the_year = now_time[0]>>> the_year2014>>> for time in now_time:...     print time... 201462821314751790


Past Time:

Import time # obtain the current time one day ago. strftime ('% Y-% m-% d % t', time. localtime (time. time ()-24*60*60) # obtain the current time 20 days ago. strftime ('% Y-% m-% d % t', time. localtime (time. time ()-20*24*60*60) # Take the first two hours of the current time 20 days ago. strftime ('% Y-% m-% d % t', time. localtime (time. time ()-20*24*60*60-2*60*60 ))

Future Time

Import time # obtain the current specific time after one day. strftime ('% Y-% m-% d % t', time. localtime (time. time () + 24*60*60) # obtain the current time of 20 days. strftime ('% Y-% m-% d % t', time. localtime (time. time () + 20*24*60*60) # Take the first two hours of the current time in 20 days. strftime ('% Y-% m-% d % t', time. localtime (time. time () + 20*24*60*60-2*60*60 ))

Past and future values of a certain unit of time

Import time # obtain the time of the last month. localtime () [1]-1 # Time of last year. localtime () [0]-1 # obtain the month time after two months. localtime () [1] + 2


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.