0
0

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.

月が英語名のタイムスタンプをdatetimeに変換し年月日で返す

Last updated at Posted at 2019-02-19

月が英語名のタイムスタンプをdatetimeに変換し年月日で返す

月が英語表記 Jan, Feb, ... の日付形式の時に、以下の方法で'1', '2', ... と変換できます。

import datetime

def getDate():
  timestamp = "Thu, 14 Feb 2019 15:10:07 +0900"
  word = timestamp.split(" ")
  date_string = word[3] + " " + word[2] + " " + word[1] # "2019 Feb 14"の形に変換
  date = datetime.datetime.strptime(date, "%Y %b %d") # %bが'Feb'を'2'に変換してくれます
  return str(date.year) + "" + str(date.month) + "" + str(date.day) + ""
  # 結果: 2019年2月14日

参考
https://docs.python.jp/2/library/datetime.html#strftime-strptime

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?