6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Python2]日付文字列→UnixTime→日付文字列

Last updated at Posted at 2013-02-04
# Python2
import datetime, time

base_data = "Feb 27 00:51:29 2021 GMT"
date_time = time.strptime(base_data, "%b %d %H:%M:%S %Y GMT")
unix_time = int(time.mktime(date_time))
gen_based = datetime.datetime.fromtimestamp(unix_time).strftime("%b %d %H:%M:%S %Y GMT")

# >>> print base_data
# Feb 27 00:51:29 2021 GMT
# >>> print date_time
# time.struct_time(tm_year=2021, tm_mon=2, tm_mday=27, tm_hour=0, tm_min=51, tm_sec=29, tm_wday=5, tm_yday=58, tm_isdst=-1)
# >>> print unix_time
# 1614354689
# >>> print gen_based
# Feb 27 00:51:29 2021 GMT

# >>> base_data == gen_based
# True
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?