JAW1025
JAW1025

Reputation: 676

Java Time questions

In java what is the most effective way to get the time so that you can compare it to another time taken later in the future?

More specifically, how can I get the hours and minutes (separately) of the current time as an integer value (as opposed to a string) to be used to compare later?

Upvotes: 1

Views: 116

Answers (2)

slugonamission
slugonamission

Reputation: 9642

Have a look at using the Java Calendar class, specifically, the .get(Calendar.HOUR) and .get(Calendar.MINUTE) methods.

Don't store the hour and minute values though, either store an instance of the Calendar class, or store the current UNIX timestamp, and compare those, obtaining the hours and minutes after performing the subtraction.

Upvotes: 4

kan
kan

Reputation: 28981

Convert to unix time, millis from the epoch. Use the jodatime, it has more powerful date-time functions. If you want use the JDK only, use java.util.Calendar.

Upvotes: -1

Related Questions