I am currently learning angular, and have a question dealing with the date time formats. I am able to set the user locale to moment.js and set it globally and use moment.js to show the date/time. But, I wanted to show the format of the locale in the placeholder of the date input. How can i do that?
Asked
Active
Viewed 3,095 times
0
-
`toLocaleString()` ? – Jordan.J.D May 04 '16 at 20:02
-
this doesn't return the format, but the date in string. I want to get the format of the date in the locale, to be displayed in the placeholder – user1722043 May 04 '16 at 20:12
-
@Thernys, Yes, it may be a possible duplicate. I was able to solve my issue, by using 'var formatL = moment.localeData().longDateFormat('L')' I had not used the _moment-with-locales.min.js_ file as well. I included that and used the localeData and it worked!! Thanks a lot, to pointing it there. – user1722043 May 04 '16 at 20:39
1 Answers
1
Good question!
What you are looking for is moment.localeData()
this call will return you a bunch of locale specific functionality. assume you are formatting using date-time formats LT, L, LL
and so on. you will need the longDateFormat
object
// assume you have set locale to be en-gb
localeData = moment.localeData()
localeData.longDateFormat()
this will return you
{
LT : 'HH:mm',
LTS : 'HH:mm:ss',
L : 'DD/MM/YYYY',
LL : 'D MMMM YYYY',
LLL : 'D MMMM YYYY HH:mm',
LLLL : 'dddd, D MMMM YYYY HH:mm'
}
here is the doc

Sitian Liu
- 1,156
- 10
- 14
-
Yes I was able to solve my issue, by using 'var formatL = moment.localeData().longDateFormat('L')' I had not used the moment-with-locales.min.js file as well. I included that and used the localeData and it worked!! @Thernys, pointed out the same stuff. Thanks – user1722043 May 04 '16 at 20:43
-
1to whoever voted down, can you please tell me why this was a bad answer? – Sitian Liu May 12 '16 at 20:45
-
-