python datetimeの変換について

658 ワード

1.グリニッジ時間への変換(1)現在の時間への変換
           GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
			nowtime = datetime.datetime.now()
			now_time=datetime.datetime.strftime(nowtime, GMT_FORMAT)

(2)ある特定の時間(例えば朝8時)を切り替える
    GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
    oclock =nowtime + datetime.timedelta(hours=- (datetime.datetime.now().hour)+8,minutes=-(datetime.datetime.now().minute),seconds=-(datetime.datetime.now().second))
	       
    oclock_8=datetime.datetime.strftime(oclock, GMT_FORMAT)

2.グリニッジ時間をxxxxx-xx-xx x:xxに変換
 datetime.strftime('%Y-%m-%d %H:%M:%S')