list comprehensions with dates

Solutions on MaxInterview for list comprehensions with dates by the best coders in the world

showing results for - "list comprehensions with dates"
Alka
31 Jul 2020
1from datetime import datetime, timedelta
2today = datetime.utcnow().date()
3ct = datetime(today.year, today.month, today.day) # current_timestamp
4time_intervals = []
5while ct.hour <= 23 and today.day == ct.day:
6  ct = ct + timedelta(minutes=10)
7  time_intervals.append('%02d:%02d' % (ct.hour, ct.minute))
8sorted_time_intervals = (sorted(time_intervals))