I've been using DateFormat to format dates, but now I need to pass the format for the locale to the jQuery Date widget. How can I get the format?
Update:
To clarify, I need to get the pattern in Java so I can output it elsewhere. e.g. in some JavaScript where I might want to create a string like this with the date format in it:
$('#datepicker').datepicker({'dateFormat':'dd/mm/yy'})
The toLocaleDateString() method returns a string with a language-sensitive representation of the date portion of the specified date in the user agent's timezone. In implementations with Intl. DateTimeFormat API support, this method simply calls Intl. DateTimeFormat .
The dates appear as, mm/dd/yyyy in the U.S. and as, dd/mm/yyyy outside the U.S. where mm is the month, dd is the day, and yyyy is the year. The time is displayed as, hh:mm:ss AM/PM, where hh is the hour, mm is minutes, and ss is seconds.
You can get the date pattern by using
((SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.UK)).toPattern()
or if you just need the date
((SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, Locale.UK)).toPattern()
API: SimpleDateFormat.toPattern(), DateFormat.getDateTimeInstance(), DateFormat.getDateInstance()
Second question is how to convert that to jQuery specific format pattern.
Java date formatting. vs jQuery DatePicker Date Formatting
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With