Skip to content

Instantly share code, notes, and snippets.

@imamdigmi
Last active January 15, 2019 16:00
Show Gist options
  • Select an option

  • Save imamdigmi/e070b5051e69c4d3ce385259d552c415 to your computer and use it in GitHub Desktop.

Select an option

Save imamdigmi/e070b5051e69c4d3ce385259d552c415 to your computer and use it in GitHub Desktop.
import pytz
from pytz import timezone
from dateutil import parser
def date_format(d):
"""Date format ISO 8601"""
if d is None or d == "":
return None
date = parser.parse(d)
timezone = pytz.timezone("Asia/Jakarta")
date_aware = timezone.localize(date)
return date_aware.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3]+"Z"
print(date_format('2018-03-17 3:12:58'))
# OUPUT: 2018-03-17T03:12:58.000Z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment