Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get default date pattern in java?

public class DefaultDateFormatPattern {
    public static void main(String[] args) {
        System.out.println(new Date());
    }
}

The output is: Thu Jan 08 10:52:56 IST 2015

Is there any method in Java to get the pattern of the date it is showing ?

like image 428
Alin Avatar asked Jan 08 '15 05:01

Alin


2 Answers

According to Java 8 toString() method of Date class the format is: EEE MMM dd HH:mm:ss zzz yyyy.

like image 95
muaz Avatar answered Sep 24 '22 13:09

muaz


You can try SimpleDateFormat.toLocalizedPattern() or SimpleDateFormat.toPattern() to get the pattern.

SimpleDateFormat format=new SimpleDateFormat();
System.out.println(format.toLocalizedPattern());
System.out.println(format.toPattern());

Pass locale to get the locale specific pattern.

Read similar post

like image 20
Braj Avatar answered Sep 22 '22 13:09

Braj