Converting unix timestamp string to readable date

前端 未结 15 2238
别跟我提以往
别跟我提以往 2020-11-22 04:30

I have a string representing a unix timestamp (i.e. \"1284101485\") in Python, and I\'d like to convert it to a readable date. When I use time.strftime, I get a

15条回答
  •  灰色年华
    2020-11-22 05:09

    Other than using time/datetime package, pandas can also be used to solve the same problem.Here is how we can use pandas to convert timestamp to readable date:

    Timestamps can be in two formats:

    1. 13 digits(milliseconds) - To convert milliseconds to date, use:

      import pandas
      result_ms=pandas.to_datetime('1493530261000',unit='ms')
      str(result_ms)
      
      Output: '2017-04-30 05:31:01'
      
    2. 10 digits(seconds) - To convert seconds to date, use:

      import pandas
      result_s=pandas.to_datetime('1493530261',unit='s')
      str(result_s)
      
      Output: '2017-04-30 05:31:01'
      

提交回复
热议问题