In addition to using the previous format, you also can display the time through the function Date(). You do not need to use the format, but through the functions provided by Java.
Below are examples of program code:
import java.lang.System;
import java.util.Date;
public class DateApp{
public static void main(String args[]){
Date today=new Date();
String days[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
System.out.println("Current time (lokal) :" + today.toLocaleString() );
System.out.println("Current time (Unix) :" + today.toString() );
System.out.println("Current time (GMT) :" + today.toGMTString() );
System.out.println("Date: "+ today.getDate());
System.out.println("Day: "+ days[today.getDay()]);
System.out.println("Hour: "+ today.getHours());
System.out.println("Minute: "+ today.getMinutes());
System.out.println("Second: "+ today.getSeconds());
}
}
Save with filename: DateApp.java
0 comments:
Post a Comment