Is there any way to get the current date and/or time? For example:
var today = new Date();
hours = today.getHours();
works in JavaScript. Is there anything like this in Java?
Printable View
Is there any way to get the current date and/or time? For example:
var today = new Date();
hours = today.getHours();
works in JavaScript. Is there anything like this in Java?
yes, as a matter of fact, the code you have is almost right.
That is basically all you need.Code:import java.util.Date;
Date today = new Date();
int hours = today.getHours();
of course, put the import at the top of your program with all the other imports. :D