Một ví dụ đơn giản về việc khởi tạo một đối tượng(object) của lớp(class) Calendar, và sử dụng nó để lấy thông tin thời gian hiện tại trên computer.
SimpleCalendarExample.java
/**
* @(#)SimpleCalendarExample.java
*
* SimpleCalendarExample application
*
* @author BUI NGOC SON
* @version 1.00 2014/2/4
*/
import java.util.Calendar;
public class SimpleCalendarExample {
public static void main(String[] args) {
//Sử dụng phương thức '.getInstance' để khởi tạo đối tượng của lớp Calendar
//Use '.getInstance' methos to create oject of lớp Calendar.
Calendar cal = Calendar.getInstance();
//Sử dụng '.getTime' phương thức để lấy thời gian hiện tại trên máy vi tính chay chương trình.
//Use '.getTime' to get current time on computer run application.
System.out.println("Today is : " + cal.getTime());
}
}
* @(#)SimpleCalendarExample.java
*
* SimpleCalendarExample application
*
* @author BUI NGOC SON
* @version 1.00 2014/2/4
*/
import java.util.Calendar;
public class SimpleCalendarExample {
public static void main(String[] args) {
//Sử dụng phương thức '.getInstance' để khởi tạo đối tượng của lớp Calendar
//Use '.getInstance' methos to create oject of lớp Calendar.
Calendar cal = Calendar.getInstance();
//Sử dụng '.getTime' phương thức để lấy thời gian hiện tại trên máy vi tính chay chương trình.
//Use '.getTime' to get current time on computer run application.
System.out.println("Today is : " + cal.getTime());
}
}
Sau khi chạy chương trình bạn sẽ được kết quả như hình bên dưới.
No comments:
Post a Comment