Hour problem in python datetime

Asked 1 years ago, Updated 1 years ago, 125 views

I don't think the question will be long.

To be exact, you should save the time as 24:00:00 in the model in python django, but if you enter 24:00:00,

Time has wrong format. Use one of these formats instead: hh:mm[:ss[.uuuuuu]].

I returned the error, so I tested it on datetime myself

>>> a = datetime.datetime(2018, 1, 11, 24, 0, 0)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: hour must be in 0..23

The hour range is from 0 to 23. I need to distinguish between 0 o'clock and 24 o'clock, is there any way?

python datetime

2022-09-22 19:31

1 Answers

https://bugs.python.org/issue10427

Please refer to the bug tracking above.

In conclusion, they say to judge by giving delta values arbitrarily, such as datetime(Y, M, D) + timedelta(1).


2022-09-22 19:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.