Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the date-time pattern from a DateTimeFormatter object

Tags:

jodatime

The usual methods used for getting the pattern in Joda for Short Date-Time by passing locale is like below:

String pattern = DateTimeFormat.patternForStyle("SS", formatLocale);

But still is there any possibility for get the pattern(eg: yy-dd-mm H:mm) from a DateTimeformatter?

DateTimeFormatter format;

Can i get/retrieve pattern from this format object once all the details(locale, zone, country) are set?

like image 590
user6374672 Avatar asked May 27 '26 16:05

user6374672


1 Answers

If you look for a generic way to retrieve the format pattern for any arbitrarily constructed formatter, then the answer is: No, not possible.

Reason is that a formatter constructed via the builder pattern allows format details which cannot be covered by any pattern. Examples:

For the builder method appendYearOfCentury(...) there is no pattern equivalent. Or the formatter exploits the option to include a custom parser which can never be covered by any pattern symbol. Similar considerations are valid for other time libraries including Java-8, too.

like image 171
Meno Hochschild Avatar answered Jun 04 '26 04:06

Meno Hochschild



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!