美文网首页
django time problem

django time problem

作者: AtrributeError | 来源:发表于2017-10-05 11:41 被阅读0次

    all time in django are timezone-sensitive(AKA. offeset-aware)
    so if you compare a django time with datetime.now()(offset_naive)
    if will give u the error as
    Can't subtract offset-naive and offset-aware datetimes

    So:
    The correct solution is to add the timezone info e.g., to get the current time as an aware datetime object in Python 3:

    from datetime import datetime, timezone

    now = datetime.now(timezone.utc)

    相关文章

      网友评论

          本文标题:django time problem

          本文链接:https://www.haomeiwen.com/subject/hdwhyxtx.html