datetime in seconds python code example
Example 1: datetime year python
import datetime
now = datetime.datetime.now()
print(now.year, now.month, now.day, now.hour, now.minute, now.second)
Example 2: python strftime iso 8601
>>> # convert string in iso 8601 date dime format to python datetime type
>>> import datetime
>>> datetime.datetime.strptime('2020-06-19T15:52:50Z', "%Y-%m-%dT%H:%M:%SZ")
datetime.datetime(2020, 6, 19, 15, 52, 50)
Example 3: python datetime to seconds
from datetime import datetime
dt = datetime.today() # Get timezone naive now
seconds = dt.timestamp()
Example 4: python weekday
df['date_time'].dt.dayofweek #gives only the index(0-monday,6-sunday)
df['date_time'].dt.weekday_name #gives the day