Created
April 20, 2016 11:43
-
-
Save jossef/f945de471f19ac801838e1683ff3adad to your computer and use it in GitHub Desktop.
python utility function to convert javascript / java date format string -> python format string
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
| def convert_to_string(dt, date_format): | |
| date_format = date_format.replace("yyyy", "%Y") | |
| date_format = date_format.replace("yy", "%y") | |
| date_format = date_format.replace("MMMM", "%B") | |
| date_format = date_format.replace("MMM", "%b") | |
| date_format = date_format.replace("MM", "%m") | |
| date_format = date_format.replace("M", "%m") | |
| date_format = date_format.replace("dddd", "%A") | |
| date_format = date_format.replace("ddd", "%a") | |
| date_format = date_format.replace("dd", "%d") | |
| date_format = date_format.replace("HH", "%H") | |
| date_format = date_format.replace("mm", "%M") | |
| date_format = date_format.replace("ss", "%S") | |
| return dt.strftime(date_format) |
Author
jossef
commented
Apr 20, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment