thieumao

GetCurrentDateTime - lấy thời gian hiện tại

Sep 18th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package test;
  6.  
  7. import java.util.Date;
  8. import java.text.DateFormat;
  9. import java.text.SimpleDateFormat;
  10. import java.util.Calendar;
  11.  
  12. public class GetCurrentDateTime {
  13.  
  14.     public static void main(String[] args) {
  15.  
  16.         DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
  17.         //get current date time with Date()
  18.         Date date = new Date();
  19.         System.out.println(dateFormat.format(date));
  20.  
  21.         //get current date time with Calendar()
  22.         Calendar cal = Calendar.getInstance();
  23.         System.out.println(dateFormat.format(cal.getTime()));
  24.  
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment