Use datetime.strftime() on years before 1900? (“require year >= 1900”)

前端 未结 4 1885
别跟我提以往
别跟我提以往 2020-12-14 00:31

I used : utctime = datetime.datetime(1601,1,1) + datetime.timedelta(microseconds = tup[5]) last_visit_time = \"Last visit time:\"+ utctime.strftime(\'%Y-%m-%d %H:%M:%

4条回答
  •  醉梦人生
    2020-12-14 00:59

    the isoformat method accepts a parameter specifing the character(s) dividing the date part from the time part of a datetime obj in its representation. Therefore:

    >>> utctime.isoformat(" ")
    '1601-01-01 00:00:00.000050'
    

    should do it. Furthermore, if you want to remove the microseconds you can operate a split.

    >>> utctime.isoformat(" ").split(".")[0]
    '1601-01-01 00:00:00'
    

提交回复
热议问题