How do I get pattern string of a SimpleDateFormat?
To format a java.util.Date object we use the SimpleDateFormat class. To get back the string pattern that were used to format the date we can use the toPattern() method of this class. package org.kodejava.text; import java.text.SimpleDateFormat; import java.util.Date; public class SimpleDateFormatToPattern { public static void main(String[] args) { SimpleDateFormat format = new SimpleDateFormat("EEEE, dd/MM/yyyy"); // […]
Article by Wayan · Source: Kode Java ↗
To format a java.util.Date object we use the SimpleDateFormat class. To get back the string pattern that were used to format the date we can use the toPattern() method of this class.
package org.kodejava.text;
import java.text.SimpleDateFormat;
import java.util.Date;
public class SimpleDateFormatToPattern {
public static void main(String[] args) {
SimpleDateFormat format = new SimpleDateFormat("EEEE, dd/MM/yyyy");
// Gets a pattern string describing this date format used by the
// SimpleDateFormat object.
String pattern = format.toPattern();
System.out.println("Pattern = " + pattern);
System.out.println("Date = " + format.format(new Date()));
}
}
The result of the program will be as follow:
Pattern = EEEE, dd/MM/yyyy
Date = Tuesday, 26/10/2021
Comments 0
Share your questions, experiences, or feedback about this article.
Sign in with Google to leave a comment.
Sign in with Google
No comments yet. Be the first to share your feedback.