Open Gravitar64 opened 2 years ago
seems to be correct, the timezones differ by 2 hours, which makes up in the resulting time difference.
try specifying the timezones explicitly for now(), as it uses the local timezone, or switch to using utcnow().
Hi,
ok, I replaced the tzinfo for start to "Europe/Berlin". But that has no effect
start = arrow.now()
start.replace(tzinfo='Europe/Berlin')
end = arrow.get('30.04.2022 13:00','DD.MM.YYYY HH:mm')
print(f'Start-Datetime: {start}')
print(f'End-Datetime : {end}')
print(f'Time-Difference: {end-start}')
Start-Datetime: 2022-04-30T12:22:02.977434+02:00 End-Datetime : 2022-04-30T13:00:00+00:00 Time-Difference: 2:37:57.022566
The correct Time-Difference should be 00:37:57......
@Gravitar64 start and end are still in different timezones, you need to specify it for both of them.
If i calculate the time difference between 2 datetime objects, the result is incorrect. Here an example:
import arrow start = arrow.get('28.04.2022 14:00','DD.MM.YYYY HH:mm' ) end = arrow.now() print(f'Start-Datetime: {start}') print(f'End-Datetime : {end}') print(f'Time-Difference: {end-start}')
Start-Datetime: 2022-04-28T14:00:00+00:00 End-Datetime : 2022-04-28T16:17:06.144073+02:00 Time-Difference: 0:17:06.144073
The correct Time-Difference should be 2:17:06......
System Info