How to convert strings and dates in python

Source: Internet
Author: User
This article describes how to convert strings and dates in python, and describes how to use time and datetime functions in Python, for more information about how to convert strings and dates in python, see the following example. Share it with you for your reference. The specific analysis is as follows:

The time and datetime functions are used here.

''' @ Author: jiangqh''' import time, datetime # date to strprint time. strftime ("% Y-% m-% d % X", time. localtime () # str to datet = time. strptime ("2009-08-08", "% Y-% m-% d") y, m, d = t [0: 3] print datetime. datetime (y, m, d)

Output result:

10: 43: 072009-08-08 00:00:00

Character:
% A short weekly
% A full English week
% B short for English month
% B full English month
% C display local Date and Time
% D date, 1-31
% H hour, 0-23
% I hour, 0-12
% M month, 01-12
% M minutes, 1-59
% J day of the year
% W indicates the day of the week
% W week
% X date of the current day
% X local day time
% Y year between and 99
Full spelling of % Y year

I hope this article will help you with Python programming.

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.