Convert timezoned date and time to Unixtime in Python2.7

What I wanted to do

I was trying to convert ISO 8601 YYYYMMDDThhmmss.SSS + 900 to Unixtime. Since % z is not supported in strptime in python2.7, date conversion using timezone is troublesome. When I use % z, I get angry as follows. ValueError: 'z' is a bad directive in format '%Y%m%dT%H%M%S.%f%z'

I tried to convert datetime <-> string with tzinfo using strftime () and strptime () However, I noticed that the conversion from JST to JST didn't have to worry about zone specifiers.

Just delete the timezone specifier

Time zone If you can't use it Erase

>>> from datetime import datetime
>>> import time
>>> int(time.mktime(datetime.strptime('20160323T204100.001+0900'.replace('+0900', ''), '%Y%m%dT%H%M%S.%f').timetuple()))                                       
1458733260

It's a bit brute force, but it's simple.

Recommended Posts

Convert timezoned date and time to Unixtime in Python2.7
Determine the date and time format in Python and convert to Unixtime
To represent date, time, time, and seconds in Python
[python] Convert date to string
How to get the date and time difference in seconds with python
How to stop a program in python until a specific date and time
Convert date timezone (time difference) in Python (from string)
Convert markdown to PDF in Python
Get the current date and time in Python, considering the time difference
Get date and time in specified format
Convert psd file to png in Python
Read big endian binary in Python and convert it to ndarray
Convert Python date types to RFC822 format
Convert from Markdown to HTML in Python
How to use is and == in Python
Convert absolute URLs to relative URLs in Python
Get and convert the current time in the system local timezone with python
3 ways to parse time strings in python [Note]
Convert FBX files to ASCII <-> BINARY in Python
Convert "number" of excel date to python datetime
How to generate permutations in Python and C ++
Convert PDFs to images in bulk with Python
Convert Windows epoch values to date with python
A clever way to time processing in Python
Send messages to Skype and Chatwork in Python
How to convert SVG to PDF and PNG [Python]
Convert exponential notation float to str in Python
How to plot autocorrelation and partial autocorrelation in python
Convert cubic mesh code to WKT in Python
Date manipulation in Python
[Python2] Date string-> UnixTime-> Date string
Get date in Python
Date calculation in python
Date calculation in Python
Introduction to Time Series Analysis ~ Seasonal Adjustment Model ~ Implemented in R and Python
Extract "current date only" and "current date and time" with python datetime.
How to convert / restore a string with [] in python
[Python] Convert decimal numbers to binary numbers, octal numbers, and hexadecimal numbers
[Python] Convert general-purpose container and class to each other
How to measure processing time in Python or Java
Convert NumPy array "ndarray" to lilt in Python [tolist ()]
Convert CIDR notation netmask to dotted decimal notation in Python
How to convert floating point numbers to binary numbers in Python
Convert the image in .zip to PDF with Python
Write tests in Python to profile and check coverage
[Python] How to sort dict in list and instance in list
Convert callback-style asynchronous API to async / await in Python
Convert / return class object to JSON format in Python
[Python] Created a method to convert radix in 1 second
Multi-digit multiplication time up to 300 million digits in python
Convert Webpay Entity type to Dict type (recursively in Python)
Summary of date processing in Python (datetime and dateutil)
[Python] Convert time display (str type) using "" "and"'" to seconds (float type) with datetime and timedelta
[Introduction to element decomposition] Let's arrange time series analysis methods in R and python ♬
[Python] Rename all image files in a specific folder by shooting date and time
To flush stdout in Python
Convert numpy int64 to python int
[Python] Convert list to Pandas [Pandas]
Login to website in Python
Date and time ⇔ character string
Convert Scratch project to Python