Using the time-period module in Python

Source: Internet
Author: User

Purpose: Learn the time module in Python to get the current or time period


Environment: Ubuntu 16.04 python3.5.2


The time module is a built-in module that can be used to get current times, dates, and to set a delay or countdown.


Import the module before you use it

Import time


Common methods are: Sleep (), strftime (), CTime ()


Sleep (t), sets the number of T, in seconds, and can have decimal points, which is understood as the number of seconds to delay execution.

Time.sleep (5)

Wait 5 seconds to continue executing the following statement.


Strftime ("), format output the current time, the parameters in quotation marks, the date of the month and seconds, multiple selection, regardless of order.

Strftime ('%y%m%d_%h%m%s ')

Returns for example 2017060713_231415 this format, each of which represents an argument between the parameters can be added as underlined.

%Y returns a 4-digit year

%y returns a 2-digit year

%m returns a 2-digit month

%H return English month abbreviation

%d returns a 2-digit day

%d Returns two bits per month/day/year format

%x with%d


When%x returns: minute: Two bits in seconds format

%H returns 24-hour system hours

%l returns 12-hour system hours

%p return AM or PM

%M return 2-digit-minute number

%s returns 2-digit number of seconds

%z return time zone such as +0800

%Z return time zone such as CST


CTime (), return the full time such as: ' Thu Jul 13 23:31:39 2017 '


This article is from the "Rickyhul" blog, make sure to keep this source http://rickyh.blog.51cto.com/10934856/1947353

Using the time-period module in Python

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.