Last active
January 15, 2019 16:00
-
-
Save imamdigmi/e070b5051e69c4d3ce385259d552c415 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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