Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package test;
- import java.util.Date;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- public class GetCurrentDateTime {
- public static void main(String[] args) {
- DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
- //get current date time with Date()
- Date date = new Date();
- System.out.println(dateFormat.format(date));
- //get current date time with Calendar()
- Calendar cal = Calendar.getInstance();
- System.out.println(dateFormat.format(cal.getTime()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment