Functions of the time module in Python: Getting times

Source: Internet
Author: User
Tags current time month name in python

In Python, its time module is very powerful, we have to learn today, less nonsense, we look at the actual effect, the following posted code:

Import Time   
print time.time ()   
print time.localtime (Time.time ())   
print time.strftime ('%y-%m-%d ', Time.localtime ())   
print time.strftime ('%y-%m-%d ', Time.localtime ())   
print time.strftime ('%y-%m-%d%h:%m:% S ', Time.localtime ())   
print time.strftime ('%y-%m-%d%i:%m:%s ', Time.localtime ())   
print time.strftime ('%y-% m-%d%h:%m:%s--%a--%c ', Time.localtime ())   
print time.strftime ('%y-%m-%d%h:%m:%s--%x--%x ', Time.localtime ())

Here is the effect:

1295099282.16
time.struct_time (tm_year=2011, Tm_mon=1, tm_mday=15, tm_hour=21, tm_min=48, tm_sec=2, Tm_wday=5, Tm_yday=15, tm_isdst=0)   
2011-01-15
11-01-15
2011-01-15
21:48:02 2011-01-15 09:48:02 2011-01-15 21:48:02--saturday--01/15/11 21:48:02
2011-01-15 21:48:02--01/15/11--21:48:02

The following is a time.strftime specific parameter description:

Time.strftime has a lot of parameters that allow you to more freely output what you want:

The following are the parameters of the Time.strftime:

Strftime (format[, tuple])-> string

Converts the specified struct_time (the default current time) to the specified formatted string output

Time date format symbol in Python:

%y Two-digit year representation (00-99)

%Y Four-digit year representation (000-9999)

%m Month (01-12)

Day of%d months (0-31)

%H 24-hour hours (0-23)

%I 12 Hours of hours (01-12)

%m minutes (00=59)

%s seconds (00-59)

%a Local Simplified Week name

%A Local Full week name

%b a locally simplified month name

%B Local Full month name

%c Local corresponding date representation and time representation

%j Day of the Year (001-366)

%p the equivalent of a local a.m. or p.m.

%u number of weeks in a year (00-53) Sunday is the beginning of the week

%w Week (0-6), Sunday for the beginning of the week

%w number of weeks in a year (00-53) Monday is the beginning of the week

%x Local corresponding date representation

%x Local corresponding time representation

%Z the name of the current time zone

%%% per se

This article from "You are a passer-by or fearless" blog, please be sure to keep this source http://world77.blog.51cto.com/414605/479081

Related Article

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.