在python中将字符串转换为offset-aware datetime

时间:2014-04-30 02:26:50

标签: python datetime datetimeoffset

我想在偏移感知时区中创建字符串时间,以便与另一个偏移感知日期时间进行比较。

from datetime import datetime, timedelta
from dateutil import parser
from dateutil.tz import gettz

today = datetime.now(gettz())  # creating a offset-aware timezone, I wanted to create manual string time also in this format

new_date = parser.parse('Apr 1 2014')  # I wanted this output to be converted into offset-aware timezone

今日变量的输出是= 2014-04-30 07:54:26.500678 + 05:30 new_date变量的输出是= 2014-04-01 00:00:00(需要将其转换为上面的格式)

转换它的任何其他方法?

0 个答案:

没有答案