Hour to get hours and minutes

Hi folks, I'm trying to find a way to get the current system time in three int variables , one for hour and one for minutes and the last for seconds but couldn't find any way to do it online. What I found was some convoluted way using a long retrieved from a unix date... Anyway, I'm new to Java and so it was too complicated for me to understand and make it work. Any help would be much appreciated.
Rodric MacOliverResearcherAsked:
Who is Participating?
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Also, I would suggest caching that LocalTime object (imagine the strange result you would get if the time ticked over the hour/minute at some point in the middle of those 3 statements), such as...

LocalTime now = LocalTime.now();
int hours = now.getHour();
int minutes = now.getMinute();
int seconds = now.getSecond();

Open in new window

Mark BullockQA Engineer IIICommented:
int hours = LocalTime.now().getHour();
int minutes = LocalTime.now().getMinute();
int seconds = LocalTime.now().getSecond();
mccarlIT Business Systems Analyst / Software DeveloperCommented:
The above assumes that you are using Java 8. Is that what you have or an older version (ie. java 6 or 7)?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.