Python Time module timing and datetime

Source: Internet
Author: User
Tags month name string format timedelta

Universal Time Format:     1. Timestamp (timestamp)  import time   time.time ()    1970-Current     2. Formatted time string     3. Tuple (struct_time) Total nine elements          time.localtime ()   View nine elements          Nine elements are as follows:            tm_year=2016,    Year             tm_mon=5,         month (1-12)             tm_mday=6,        Day (1-31)              tm_hour=14,      hours (0-23)              tm_min=32,       min (0-59)              tm_sec=12,       seconds (0 to 61  (60 or 61  are leap seconds)              tm_wday=4,       weeks (0-6)              tm_yday=127,     The first day of the Year (1-266)             tm_isdst=-1       is daylight saving time: The default is-1 timezone setting:     1.UTC (Coordinated universal time, World coordination Time) is Greenwich Astronomical time, world standard Time. China is utc+8.     2.DST (daylight saving time) is daylight saving time. Time Module Method: Time.time ()       view timestamp time.timezone ()   View timeframe (unit: seconds) Time.sleep ()       Stop seconds Timestamp conversion narimoto Group format: time.gmtime ()     timestamp conversion narimoto Group type format; default conversion current UTC time. Time.localtime () timestamp conversion Cheng Yuanju type format; default conversion local utc+8 time. Tuple time format converted to timestamp time.mktime ()     tuple format converted to timestamp format time; print (Time.mktime (Time.localtime ())) Tuple time format converted to string time.strftime ()   tuple format converted to latticePrint (Time.strftime ("%y-%m-%d %h:%m:%s", X))   x is a tuple format, no x default current time string conversion Narimoto group time format time.strptime ()   formatted string conversion narimoto group format; print (Time.strptime ("2017-10-30 10:30:30", "%y-%m-%d %h:%m:%s")) Timestamp converted to string format: print (Time.asctime ())             return string time format (week   month   Day   hours: minutes: Seconds   years) Time.ctime ()                       return string time format (weeks   month   Day   hours: minutes: seconds   years) " DateTime Module Method: Import datetime,timeprint (Datetime.datetime.now ())                         #返回现在的时间print ( Datetime.date.fromtimestamp (Time.time ()))       #时间戳转成日期格式print (Datetime.datetime.now () + datetime.timedelta (3))     #当前日期 + 3 days print (Datetime.datetime.now () + datetime.timedelta ( -3))    #当前日期-3 days print (DatetiMe.datetime.now () +datetime.timedelta (hours=3))    #当前时间 + 3-hour print (Datetime.datetime.now () + Datetime.timedelta (minutes=-30))    #当前时间-30 min now_time = datetime.datetime.now () print (Now_ Time) print (Now_time.replace (year=2016,month=6,day=6,hour=6,minute=6,second=6))     #时间替换时间格式符号参照% a     local (locale) simplified week name%a     Local full week name%b     Local simplified month name% b     Local Full month name%c     local corresponding date and time represents the day ordinal of the%d     one month (01  - 31)%h     hours of the day (24-hour system, 00 - 23)%i     The first few hours (12 hours, 01 - 12)%j     the Day of the Year (001 - 366)%m     Month (01 - 12)%m     minutes (00 - 59)%p     local AM or PM's corresponding character     %s     seconds (01 - 61)      two%u      the number of weeks in a year. (00 - 53Sunday is the beginning of one weeks. All days before the first Sunday are placed in the No. 0 week.      three%w     the day of the one week (0 - 6,0 is Sunday)      three%w      and%u are basically the same, unlike the%w, which began in Monday for one weeks. %x     Local corresponding date%x     local corresponding time%y     remove the year of the Century (00 -  99)%y     full year%z     the name of the time zone (if not present as a null character)%%     '% ' character three time format relationship transformation:

Python Time module timing and datetime

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.