-5

I need the localized date format pattern string i.e. 'dd mmmm yyyy' or 'mmmm dd, yyyy'.

I need to pass this string to a external plugin that uses it for showing dates.

Note: I do not need to format a date. I need to get the format "pattern string" of the user's locale.

blackspacer
  • 343
  • 6
  • 15
  • Maybe use to *toLocaleString()* --> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString – Mohammed Joraid Aug 01 '17 at 11:44
  • Possible duplicate of [How to format a JavaScript date](https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date) – Maxim Kuzmin Aug 01 '17 at 11:44
  • @Maxim I do not need to format a date. I need to get the format "pattern string" of the user's locale. – blackspacer Aug 01 '17 at 12:01
  • @Tushar There are multiple ways to show the date in a format. BUT I do not want that. I want the user's locale date format string i.e. 'mmmm dd, yyyy' or something. And for that I haven't found any solution. – blackspacer Aug 01 '17 at 12:03
  • @Stackoverflow mods/police See Ben's answer below and read questions carefully before downvoting. – blackspacer Aug 01 '17 at 12:09
  • I'm still confused why not use your server side to handle the locale? For example in .NET framework it handles localisation very simple, I assume other server side language have similar functionality. – penleychan Aug 01 '17 at 12:13
  • I have upvoted because I'm now solving similar problem... :) Have you handled that? And how? – Frimlik Oct 06 '22 at 11:03
  • @Frimlik I eventually used momentjs as there was no native approach possible without help of a library. – blackspacer Oct 17 '22 at 12:57

1 Answers1

2

It does not seem like it's possible to do this natively in JavaScript - you could either import a library like Moment.js or you could use a static map from a resource such as this one.

Ben Elliott
  • 1,650
  • 14
  • 18
  • Thanks Elliot for confirming because I too was unable to find a way using native Javascript. Using a static map would be hardcoding and prone to errors. It seems like momentjs would be the best way to go. I will wait for other answers to see if there is a possible way in native javascript. – blackspacer Aug 01 '17 at 12:08