Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert millisecond time stamp to normal date in Python?

I have a data frame with a column with values in millisecond time stamp.(df['Millisecond'])

What I want to do is to convert all values of that column into normal dates. Ex. 2017-04-27 04:55:00

like image 736
R. Trading Avatar asked May 27 '17 04:05

R. Trading


2 Answers

You need python's datetime package to do that:

import datetime

date = datetime.datetime.fromtimestamp(milliseconds/1000.0)

date = date.strftime('%Y-%m-%d %H:%M:%S')
like image 176
Akash Wankhede Avatar answered Nov 01 '22 06:11

Akash Wankhede


you can do this by using to_datetime function https://pandas.pydata.org/docs/reference/api/pandas.to_datetime.html.

df['Millisecond'] = pd.to_datetime(df['Millisecond'], unit='ms')
like image 14
Maninder Singh Avatar answered Nov 01 '22 07:11

Maninder Singh