Last active
March 29, 2018 10:04
-
-
Save linuxkathirvel/4a01bd3195c6b33720fe0158d0439428 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 datetime | |
# strptime() is used for converting a string to a datetime object. | |
# strftime() is used for converting datetime object to formatted string | |
date_string = "2017-08-10 17:32:25" | |
# To convert as Python DateTime object | |
python_date_time_object = datetime.datetime.strptime(date_string, "%Y-%m-%d %H:%M:%S") | |
# If you want date time string as give format from Python DateTime object | |
# '2017/08/10 05:32:25 PM' | |
string_from_python_time_object = datetime.datetime.strftime(s1, "%Y/%m/%d %I:%M:%S %p") | |
# https://stackoverflow.com/questions/31955761/converting-python-string-to-datetime-obj-with-am-pm?lq=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment