I am making a simple clock using Java that display......
The current time in hours:minutes:seconds and the current date.
I googled for this,but I get codes in applet form. I don't know how to start.
I have this code below that returns the date and time as a string. It get the local system time.
My problem is to display it in the GUI with the display moving.
I tried to put a Label in the GUI and set it with the returned value
It displays but its just stationary.Code:TimeLabel.setText(DateTime.now);
I tried to use an infinite loop on it but the code wouldn't build.
Also, Can I use the returned String to insert in a MSSQL database?Code:public class DateTime{ public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss"; public static String now() { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW); return sdf.format(cal.getTime()); } }




Reply With Quote