Python example-About time module

Source: Internet
Author: User

October 17, 2015 09:28:42 python-time

Visit Web site If you do not want to cache the back of the add? t=123 if the site is attacked should do, do the traffic cleaning, analysis package, the right to let go, or abandon. If the station bandwidth of the attack is full, see if the operator can help with the cleaning. The general website has CDN, otherwise cannot carry. Cdn:http://baike.baidu.com/link?url=xb3kat8hgckeiwekvq0zn59yxxohdem1a_ B2aarludc4ufhkwfrtp3vghhhqvjklzdshvwcwytjta9rnzfgefa time module. Conversion Timestamp: time.strftime ('%y-%m-%d%h-%m-%s ', Time.localtime ()) when grabbing some websites or databases, the time of return is sometimes different, there is time stamp, there are some standard time. Therefore, the time module in Python is required for processing.
#!/usr/bin/python#Coding:utf-8ImportTimeunix_timenow=Int (time.time ())Print 'Current time:%d'%Unix_timenowtimenow= Time.strftime ('%y-%m-%d%h:%m:%s', Time.localtime (unix_timenow))Print 'Current Standard Time:%s'%Timenowtime.sleep (3) Unixtime= Time.mktime (Time.strptime (TimeNow,'%y-%m-%d%h-%m-%s'))Print 'Unix Time:%s'%current time in Unixtime:1445047077Current Standard Time:2015-10-17 09:57:57Unix Time:1445047077.0[Finishedinch3.2S]
The time module function introduces Time.time () #返回当前时间的unix时间戳time. Sleep () #sleep时间time. LocalTime (unixtime) #将一个时间戳转换成一个当前时区的struct_time, If the seconds parameter is not entered, the current time is the conversion standard Time.strftime (Struct_time,string_format) #将指定的struct_time根据格式化字符串输出time. Mktime (struct _time) #将struct_time时间转换为unix时间time. Strptime (string_time,string_format) #将格式化时间转换为struct_time python in time date      Formatting symbols:%y Two-digit year (00-99)%y Four-digit year represents (000-9999)%m month (01-12) Day (0-31)%H 24-hour hours (0-23)%I 12-hour hours (01-12)%M minutes (00=59)%s seconds (00-59)
#!/usr/bin/pythonImport Time#1. Convert 2015-1-16 12:00:00 to Unix time and calculate the format time and Unix time 3 days before this time. defMain (): Time1='2015-1-16 12:00:00'unixtime1= Time.mktime (Time.strptime (time1,'%y-%m-%d%h:%m:%s')) Print '1:unix Timestamp:%s'%unixtime1 unixtime2= Unixtime1-60*60*24*3Print '1:3 days ago Timestamp:%s'%unixtime2 time2= Time.strftime ('%y-%m-%d%h:%m:%s', Time.localtime (unixtime2))Print '1:3 days ago Format time:%s'%time2if __name__=='__main__': Main ()

October 17, 2015 20:52:23

Python example-About time module

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.