python - datetime - how to add seconds to Epoch? -
i not know how tackle this. need first turn str() datetime object, convert epoch time add number of seconds turn date in formatted object. sample of str is:
"2016-11-04t03:02:00z"
i'm guessing regex break str()??
use timedelta object, e.g:
from datetime import datetime, timedelta timestring_format = '%y-%m-%dt%h:%m:%sz' dt = datetime.strptime('2016-11-04t03:02:00z', timestring_format) ndt = dt + timedelta(seconds=5) print datetime.strftime(ndt, timestring_format) see docs https://docs.python.org/2/library/datetime.html , make sure timestring_format string correct.
Comments
Post a Comment