Is it possible to get the pattern string from a joda-time DateTimeFormatter?
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd");
String originalPattern = formatter. ???
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Joda Time does not provide a way to get the original pattern from a DateTimeFormatter. One reason is probably that a DateTimeFormatter wasn’t necessarily created from a pattern; for example
DateTimeFormat.forStyle()does not use patterns at all.However if you always use patterns, then you could wrap the
DateTimeFormatclass to record the pattern when theDateTimeFormatteris constructed. That way you can look it up later with a simple static method. For example:Then you can do this: