How to get the local date and time in Java

2 Answers

0 votes
package javaapplication1;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Example {
    public static void main(String[] args) {
			
        Date curDate = new Date();
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM yyyy zzzz", Locale.ENGLISH);
	        String DateToStr = sdf.format(curDate);
	        System.out.println(DateToStr);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
}
 
 
/*
run:
 
13 January 2016 Israel Standard Time
 
*/

 



answered Jan 13, 2016 by avibootz
0 votes
package javaapplication1;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Example {
    public static void main(String[] args) {
			
        Date curDate = new Date();
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM yyyy hh:mm:ss", Locale.ENGLISH);
	    String DateToStr = sdf.format(curDate);
	    System.out.println(DateToStr);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
}
 
 
/*
run:
 
13 January 2016 11:12:35
 
*/

 



answered Jan 13, 2016 by avibootz

Related questions

...