Advertisement
felix_de_suza

LocalDateTime

May 13th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.util.Date;
  2. import java.text.DateFormat;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Calendar;
  5. import java.time.LocalDateTime;
  6.  
  7.  
  8. public class PrintCurrentDateTime {
  9.  
  10.     public static void main(String[] args) {
  11.          
  12.            DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
  13.            //get current date time with Date()
  14.            Date date = new Date();
  15.            System.out.println(dateFormat.format(date));
  16.      
  17.            //get current date time with Calendar()
  18.            Calendar cal = Calendar.getInstance();
  19.            System.out.println(dateFormat.format(cal.getTime()));
  20.            
  21.            LocalDateTime dt = LocalDateTime.now();
  22.            System.out.println(dt);
  23.      
  24.       }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement