convert timestamp to date pandas code example

Example 1: pd.to_datetime python

import pandas as pd
date='2020/11/26 12:00:00'
date_time=pd.to_datetime(date, format='%Y/%m/%d %H:%M:%S')

Example 2: pandas change dtype to timestamp

pd.to_datetime(df.column)

Example 3: convert timestamp to datetime

from datetime import datetime

timestamp = 1545730073
dt_object = datetime.fromtimestamp(timestamp)

print("dt_object =", dt_object)
print("type(dt_object) =", type(dt_object))

Example 4: convert timestamp to datetime

from datetime import datetime

# current date and time
now = datetime.now()

timestamp = datetime.timestamp(now)
print("timestamp =", timestamp)

Tags:

Java Example