how to create datetime from a negative epoch in Python

后端 未结 3 1020
既然无缘
既然无缘 2021-01-18 02:40

First timer on StackExchange.

I am working with ArcGIS Server and Python. While trying to execute a query using the REST endpoint to a map service, I am getting the

3条回答
  •  暖寄归人
    2021-01-18 03:09

    You can accomplish this using the datetime module's datetime and timedelta functions.

    The other answers divide the timestamp by 1000 to convert milliseconds to seconds. This is unnecessary, since the timedelta function can take milliseconds directly as a parameter. It might therefore be cleaner to do something like this:

    datetime.datetime(1970, 1, 1) + datetime.timedelta(milliseconds=-3739996800000)
    

    which gives datetime.datetime(1851, 6, 27, 0, 0), as you'd expect.

提交回复
热议问题