Python: Convert time in any format to Unix Timestamp)

Source: Internet
Author: User
Tags month name

UNIX timestamp: the number of seconds that have elapsed since midnight on January 1, January 1, 1970 (UTC/GMT), regardless of the leap second.

Take 25/JUL/2012: 13: 26: 58 as an example.

Python program:

Import time

Import datetime

X = datetime. datetime. strptime ('25/JUL/2012: 13: 26: 58 ',' % d/% B/% Y: % H: % m: % s ')

Time. mktime (X. timetuple ())

Output:

1343194018.0

Note:

Description of formatting the time string in the strptime function:

% 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

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.