2

I have a date that I want to display to the user, and the format should be dynamic and based on the user. If I do this I get a format that doesn't fit every user.

var prettyDate = originalDate.format('dd MMM yyy, hh:ss');

For example, in Sweden we would like it displayed as 2014-03-04 but another country would want it as 4/3 2014 So instead of explicitly writing the format in the code, I want to get the preferred date format for the current user. My idea was that I could maybe use the culture found in _spPageContextInfo, or something in SP.DateTimeUtil, but I can't find anything.

1 Answer 1

3

Microsoft Ajax library also contains Date.localeFormat Function that formats a date by using the current culture.

Example:

var prettyDate = originalDate.localeFormat('dd MMM yyy, hh:ss');
console.log(prettyDate);
2
  • But that still means I have to put in a format string and I don't want to do that. What I want is to use the same rendering of the date as used by SharePoint default, for example in a list
    – stinaq
    Commented Mar 4, 2014 at 9:58
  • 3
    @stinaq did you see the example dateVar.localeFormat(Sys.CultureInfo.CurrentCulture.dateTimeFormat.ShortDatePattern);? As a last resort perhaps look at momentjs.com
    – eirikb
    Commented Mar 4, 2014 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.