Python DateTIme

Submitted by code_admin on Sat, 01/12/2019 - 12:07

import pytz
import datetime
from dateutil.parser import parse

Get a UTC datetime object from isoformat string

  1.     dt = parse(result2JSON['jwtData']['TokenExpiry'])
  2.     dateTimeObjFromJSON = dt.astimezone(pytz.utc)
  3.     print(dateTimeObjFromJSON)

Output iso

  1. self.lastRunDate.isoformat()

Time Addition

  1.     createPersonTime = datetime.now(pytz.timezone("UTC"))
  2.     updatePersonTime = createPersonTime + timedelta(seconds=int(12))

Flask field

  1. 'nextScheduledRun': fields.DateTime(dt_format=u'iso8601', description='Next scheudled run'),

Tags

RJM Article Type
Quick Reference