Getting current Hour/Minute/Second into different variables
I'm a beginner looking for a way to initialize three seperate variables with the current Hour, Minute, and second. Here's what I've been able to do so far, and after that, here's what stumps me:
THIS WORKS:
import java.util.*; //import java utility package
public class FullDate {
public static void main(String[] args) {
//create a Calendar Object
Calendar calendar = Calendar.getInstance();
//declare and initialize local variable "fullDate" with current long date
Date fullDate = calendar.getTime();
//print to screen the value in fullDate variable
System.out.println("current date is: " + fullDate);
}
}
FullDate Output:
current date is: Sat Aug 24 14:48:38 CST 2002
(OKAY, SO FAR, SO GOOD)
NOW, HERE'S THE PROBLEM:
import java.util.*; //import java utility package
public class GetCurrentTime {
public static void main(String[] args) {
//create a Calendar Object
Calendar calendar = Calendar.getInstance();
//declare and initialize local variable "hour" with current hour
int hour = calendar.HOUR_OF_DAY;
//declare and initialize local variable "minute" with current minute
int minute = calendar.MINUTE;
//declare and initialize local variable "second" with current second
int second = calendar.SECOND;
//print to screen the value in hour variable
System.out.println("current hour is: " + hour);
//print to screen the value in minute variable
System.out.println("current minute is: " + minute);
//print to screen the value in second variable
System.out.println("current second is: " + second);
}
}
GetCurrentTime Output
current hour is: 11
current minute is: 12
current second is: 13
THE ACTUAL TIME I RAN THIS WAS 2:32 pm.
I'm not using a Date variable type as I did in the "FullDate" source, because I need to use the hour/minute/second variables as ints later on in the program. Not only that, but I DID try to change them from "int" types to "Date" types, but I got a compiler error which indicated "Incompatible type for declaration. Can't convert int to java.util.Date. Date minute = calendar.MINUTE;"
As anyone can probably tell, I'm very new to this and when I've tried to research these erros via the API documentation I'm (almost) completely lost. Additionally, my learning platform is a G4 Macintosh - God, I hope the mac isn't the issue here! Any guidance will is greatly appreciated!

