Moment.js get date format for input field of input field
I am using moment.js in my application. When the user logs into the application, their locale is set:
moment.locale(userLocale);
I want to add a placeholder to the input field that represents the expected date format, depending on the user's locale:
<input type="text" placeholder="dd/mm/yyyy" />
Is there a way to get the string 'dd / mm / yyyy' from moment
?
+3
source to share
2 answers
You can access the language function via
var currentLocaleData = moment.localeData();
You can then get the full format of the abbreviated date and time formats using the method longDateFormat()
:
var format = currentLocaleData.longDateFormat('L');
-1
source to share