r/javahelp • • Oct 31 '25

Homework How are numbers compared as a String?

I'm working on this project, and I'm checking whether something occurs before a specific time. I'm doing this by converting the times to Strings, then comparing them against each other (yes I'm aware it's not ideal, bear with me).
The issue is that it says that '10:00 < 09:00'. Why is that?

0 Upvotes

24 comments sorted by

View all comments

Show parent comment

1

u/vegan_antitheist Nov 01 '25

Note that '10:00 < 09:00' could be correct. It's about 10:00 now here in Switzerland but when it's 09:00 in the USA it will be later. So 10:00 here is before 09:00 over there.
With a time zone you can't just compare hours and minutes. That's just not how time works.