I am writing a program that checks the next bus from a timetable obtained from the net.
I want to compare the time of the timetable string and the time of the day that can be obtained with datetime
So the time of the string is a time type? I want to convert it to, but the date information is also included.
How can I make comparisons only in time?
import datetime #str = ['06: 03 ', '06: 09', '06: 13 ', '06: 21', '06: 26 ', '06: 31', '06: 38 '...]' now = datetime.datetime.now () for i in range (0,83) t = datetime.datetime.strptime (str [i], '% H:% M') if now<t: next = t break print (next)
The date is entered in the above program.Supplemental information (FW/tool version etc.)
Please provide more detailed information here.
Answer # 1
datetime.datetime.time (hour, minute)
You can use to create a time object with a specified time only.
Also, datetime.datetime objects have a time () method,
now = datetime.datetime.now () now.time ()
You can get a time object like this.
In addition, these objects are
You can get only hours and minutes like this.
- python 3x - i want to find out if there is a specific hiragana in the string
- i want to extract the date and time from a string in python
- python - how to format (extract) only the json part of a character string that contains some json
- i want to delete a specific word from a string using a regular expression python
- if a specific word is described in the python string, set a flag and repeat it multiple times
- python - i want to compare two csv files and output one file
- i want to change the 24:00 python pandas string to 00:00 the next day
- i want to change a string to hexadecimal in python
- i want to extract specific information from a python string
- i want to convert "array string" to an array in python
- i want to extract one character string of text that exists in multiple files with python
- python - sum of numbers by inputting a character string
- i want to aggregate a specific character string by day using the python groupby count function etc
- python - i made a code to search a website tag as a string, but can it be simplified?
- how to convert a string to date type in python
- python 3x - i can't convert the date ("2018/12/31") string in series to datetime with python
- (python) how do i split a string into "words in a list"?
- python 3x - display a specific string in a text file
- python - i want to delete non-multiples from the array string (sequence + \ n)
- python error compare with future stock price