는 날짜 개체에서 시간대 (tzinfo)를 제거하려면 화살표 객체를 datetime 객체로 변환 한 다음 위의 예제와 동일한 작업을 수행합니다.
# <Arrow [2014-10-09T10:56:09.347444-07:00]>
arrowObj = arrow.get('2014-10-09T10:56:09.347444-07:00')
# datetime.datetime(2014, 10, 9, 10, 56, 9, 347444, tzinfo=tzoffset(None, -25200))
tmpDatetime = arrowObj.datetime
# datetime.datetime(2014, 10, 9, 10, 56, 9, 347444)
tmpDatetime = tmpDatetime.replace(tzinfo=None)
왜 이렇게할까요? 한 가지 예는 mysql이 DATETIME 타입을 가진 타임 존을 지원하지 않는다는 것이다. 따라서 sqlalchemy와 같은 ORM을 사용하면 datetime.datetime
개체에 데이터베이스에 삽입 할 때 시간대가 제거됩니다. 해결 방법은 사용자의 datetime.datetime
개체를 UTC로 변환하는 것입니다 (데이터베이스의 모든 항목이 표준 시간대를 지정할 수 없기 때문에 UTC이므로 시간대가 제거 된 데이터베이스에 삽입하거나 직접 제거하십시오). 또한 은과 비교할 수 있습니다. datetime.datetime
개체는 시간대를 인식하고 다른 개체는 시간대를 알지 못하는 개체와 비교하십시오.
##############################################################################
# MySQL example! where MySQL doesn't support timezones with its DATETIME type!
##############################################################################
arrowObj = arrow.get('2014-10-09T10:56:09.347444-07:00')
arrowDt = arrowObj.to("utc").datetime
# inserts datetime.datetime(2014, 10, 9, 17, 56, 9, 347444, tzinfo=tzutc())
insertIntoMysqlDatabase(arrowDt)
# returns datetime.datetime(2014, 10, 9, 17, 56, 9, 347444)
dbDatetimeNoTz = getFromMysqlDatabase()
# cannot compare timzeone aware and timezone naive
dbDatetimeNoTz == arrowDt # False, or TypeError on python versions before 3.3
# compare datetimes that are both aware or both naive work however
dbDatetimeNoTz == arrowDt.replace(tzinfo=None) # True