Last active
March 14, 2016 01:22
-
-
Save buptxge/1659fad862ef3f8ec957 to your computer and use it in GitHub Desktop.
Python get structed time string
This file contains 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 | |
import time | |
#Get now time string | |
timestr = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") | |
#Calc time delta | |
t1 = datetime.datetime.now() | |
time.sleep(3) | |
t2 = datetime.datetime.now() | |
timedelta_str = str(t2-t1) | |
#Get datetime from a string and compare two datetime | |
t3 = datetime.datetime.strptime("2016-03-16 09:01:02","%Y-%m-%d %H:%M:%S") | |
t4 = datetime.datetime.strptime("2016-03-15 18:03:27","%Y-%m-%d %H:%M:%S") | |
result = t3<t4 #False | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment