Python Common Time Acquisition method

Source: Internet
Author: User

The code is as follows:

1 Importdatetime2 Import Time3 4Datetime_format ="%y-%m-%d%h:%m:%s"5Date_format ="%y-%m-%d"6 7 defget_now_timestamp_13 ():8     returnInt (time.time () *1000)9 Ten defget_now_date (): One     returntime.strftime (date_format) A  - #the type returned using Datetime.date.today () is a datetime type and needs to be converted to a string type - defget_yesterday (): theToday =Datetime.date.today () -     returnSTR (Today-datetime.timedelta (Days=1)) -  - defget_now_datetime (): +     returntime.strftime (Datetime_format) -  + deftimestamp_to_datetime (timestamp): A     #The timestamp- to-date-time format is converted to one of the following tuple, then to DateTime via Strftime (format,tuple), to timestamp by Strptime (Datetime,format) at     #time.struct_time (tm_year=2017, tm_mon=12, tm_mday=20, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=354,tm_ Isdst=-1) -     returnTime.strftime (Datetime_format,time.localtime (timestamp/1000)) -  - defdatetime_to_timestamp_13 (datetime): -     returnInt (Time.mktime (Time.strptime (datetime,datetime_format)) *1000) -  in defdatetime_to_timestamp_10 (datetime): -     returnInt (time.mktime (Time.strptime (Datetime,datetime_format))) to  +  - if __name__=='__main__': the     #print (Time.localtime ()) *     #Print (Time.strptime ("2017-12-20", "%y-%m-%d")) $     #Print (Time.mktime (Time.strptime ("2017-12-20", "%y-%m-%d" )))Panax Notoginseng     #Print (Time.localtime (1513699200)) -     #print (1513699210789/1000) the     #Print (Time.strftime ("%y-%m-%d%h-%m-%s", Time.localtime (1513699210789/1000))) +  A     #Print (Timestamp_to_datetime (get_now_timestamp_13 ())) the     #Print (Datetime_to_timestamp (Timestamp_to_datetime (get_now_timestamp_13) )) +     #print (get_now_timestamp_13 ()) -     Print(Get_now_date ()) $     Print(Get_now_datetime ())

Python Common Time Acquisition method

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.