How do I format time? Python Current time formatting action show

Source: Internet
Author: User
For today's article, let's take a look at Python's python time formattingPart of the content, python formattingThis aspect of the date and time this aspect because of the use of relatively small, so may be less research on this aspect, today we come to talk about python date formattingOne aspect of knowledge.

Formatted Date: We can use the Strftime method of the time module to format the date with the following code:

Time.strftime (format[, T])

It doesn't seem to be very difficult, so let's try this code next.

Take him into the following example to try it out:

#!/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", t Ime.localtime ())  # formatted into Sat Mar 28 22:24:24 2016 form print time.strftime ("%a%b%d%h:%m:%s%Y", Time.localtime ())   # will format string converted to timestamp a = "Sat Mar 22:24:24" Print Time.mktime (Time.strptime (A, "%a%b%d%h:%m:%s%Y"))

Take a look at the answers you get after typing:

2018-08-14 17:05:32tue 14 17:05:32 20181459175064.0

It seems to be good to finish the expected effect, interested friends can try it on their own. See if the output time is your time.

In this article, we understand how to format their current time, in fact, this operation is quite simple, do not understand the words can actually try to do, after all, hands-on practice is the best way to verify the learning. Finally, I hope that this article will give you a little help in learning about Python.

For more information, please visit the PHP Chinese Web Python tutorial section.

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.