Python Date and time

Source: Internet
Author: User
Tags local time

There are many functions under the time module that can convert common date formats. such as function time.time () to get the current timestamp,  example: #!/usr/bin/python#-*-coding:utf-8-*-import time;  # Introducing Time Module TICKS = Time.time () print "Current timestamp is:", ticks output is current timestamp: 1459994552.51  get current time #!/usr/bin/python#-*-coding:utf-8-*-import Timelocaltime = Time.localtime () print "local time:", localtime  output to local time: Time.struct_time (tm_year=2018, tm_mon=3, tm_ Mday=12, tm_hour=22, tm_min=21, tm_sec=51, tm_wday=0, tm_yday=71, tm_isdst=0)    get formatted time #!/usr/bin/python#- * * Coding:utf-8-*-import timelocaltime = time.asctime () print "local time:", localtime  output to local time: Mon Mar 12 22:24:06 20 18  example  #!/usr/bin/python#-*-coding:utf-8-*- import time # formatted as 2016-03-20 11:45:39 form print Time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ())  # formatted as Sat Mar 28 22:24:24 2016 form print time.strftime ("%a%b%d% h:%m:%s%Y ", Time.localtime ())  # convert format string to timestamp a =" Sat Mar 22:24:24 "Print Time.mktime (Time.strptime (A,"%a%b %d%h:%m:%s%Y "))   output of 2018-03-22:25:29mon Mar 22:25:29 20181459175064.0   get a month calendar The  calendar module has a wide range of methods for working with calendar and monthly calendars, such as printing monthly calendars for a month: #!/usr/ bin/python#-*-coding:utf-8-*-import calendarcal = calendar.month (1) print "The following output January 2016 calendar:" Print cal; & nbsp;        

Python date and time

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.