user1471980
user1471980

Reputation: 10636

how do you convert current date time in NY time to epoch in python

I need to convert current date time to epoch time in python.

I have tried this, but I am not sure is this tz="New_York/Americas". Is below right?

import time

epoch_time = int(time.time())

Upvotes: 1

Views: 115

Answers (1)

Vimalraj Selvam
Vimalraj Selvam

Reputation: 2245

You can use python's calendar module for this.

from datetime import datetime
from calendar import timegm

current_time = datetime.utcnow()
epoch_time = timegm(current_time.utctimetuple())

For more, visit calendar's timegm.

Upvotes: 2

Related Questions