Time formatting for python

Source: Internet
Author: User
Tags month name

For time formatting like 'wed, 11 Apr 2012 09:37:05 + 123', the following solutions are provided:

>>> Date = 'wed, 11 Apr 2012 09:37:05 + 0800'
>>> Dd = datetime. datetime. strptime (date, '% A, % d % B % Y % H: % m: % S % Z ')
>>> Dd. strftime ('% Y-% m-% d % H: % m: % s ')

The function for formatting the date and time in python is datetime. datetime. strftime (); Convert from string to date type function: datetime. datetime. strptime (), two functions are involved in the format string of the date and time, as shown below:

% A abbreviated weekday name % A full weekday name % B abbreviated month name % B full month name % C Date And Time Representation appropriate For Locale % D day of month as decimal number (01-31 ) % H hour In 24-hour format (00-23 ) % I hour In 12-hour format (01-12 ) % J day of year as decimal number (001-366) ) % M month as decimal number (01-12 ) % M minute as decimal number (00-59 ) % P current locale ' S a. m./P. M. Indicator for 12-hour clock % S second as decimal number (00-59 ) % U week of year as decimal number, with Sunday as first day of week (00-51 ) % W weekday as decimal number (0-6; Sunday Is  0) % W week of year as decimal number, with Monday as first day of week (00-51 ) % X date Representation For  Current locale % X Time Representation For  Current locale % Y year without Century, as decimal number (00-99 ) % Y year with Century, as decimal number % Z, % Z time-zone name Or Abbreviation; no characters If Time Zone Is  Unknown % Percent sign

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.