2017/08/05

Python - Date Time Comparison

This post is about how to compare system time against a pre-defined time.

1
2
3
4
5
6
7
8
9
import datetime
#print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
str_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print str_time

if "09:00" in str_time:
   print "True"
else:
   print "False"

References:

Python - How to get current date time and format its output
http://wei48221.blogspot.tw/2017/03/python-how-to-get-current-date-time-and.html

How to determine whether a substring is in a different string
https://stackoverflow.com/questions/7361253/how-to-determine-whether-a-substring-is-in-a-different-string

No comments:

Post a Comment