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.
Cheers.
Rodric MacOliverResearcherAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark BullockQA EngineerCommented:
int hours = LocalTime.now().getHour();
int minutes = LocalTime.now().getMinute();
int seconds = LocalTime.now().getSecond();
0
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)?
0
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.