Convert numpy.datetime64 to string object in python

后端 未结 6 959
無奈伤痛
無奈伤痛 2020-11-30 03:45

I am having trouble converting a python datetime64 object into a string. For example:

t = numpy.datetime64(\'2012-06-30T20:00:00.000000000-0400\         


        
6条回答
  •  误落风尘
    2020-11-30 04:02

    Building on this answer I would do the following:

    import numpy
    import datetime
    t = numpy.datetime64('2012-06-30T20:00:00.000000000')
    datetime.datetime.fromtimestamp(t.item() / 10**9).strftime('%Y.%m.%d')
    

    The division by a billion is to convert from nanoseconds to seconds.

提交回复
热议问题