1

I need date format of site, I can get date separator using get_regionalSettings() and get_dateSeparator() .

I tried get_dateFormat() but it returns "1".

I need to know date format of particular site "dd/mm/yyyy" , "mm/dd/yyyy" or whatever the default date time format is set in SharePoint site.

How can I get that using JSOM?

2
  • I'm not sure actually, never used _api/web/RegionalSettings/dateFormat. But it return 0 from webs with locale US (mmddyyyy)and 1 from my web with Norwegian (ddmmyyyy). You could check if 1 is ddmmyyyy and vice versa. Commented Sep 21, 2017 at 7:10
  • @AndersAune I think there are more formats than ddmmyyyy and mmddyyy, so it won't work, and also what about date separators?
    – codemirror
    Commented Sep 22, 2017 at 5:46

3 Answers 3

1

The first step is to figure out what time zone it is displaying. There are two types of Regional Settings that specify the time zone:

  • Regional Settings in User Profile Settings
  • Regional Settings under each site

May b try this link How to Get the Time Zone in SharePoint Online Using JSOM

0

I was facing same issue in my SPFX webpart. I was trying to show date format based on regional settings of current site.

So at first I take current culture name. Culture name can be like "en-US", "nn-NO" etc. Then I use moment to format the date. Check below example:

const currentCultureName = props.context.pageContext.legacyPageContext.currentCultureName;
moment.locale(currentCultureName);
const dateString = moment(new Date()).format('L');

If the answer is helpful, please upvote.

-1

Add a reference to moment js. This can be downloaded from https://momentjs.com/downloads/moment.js .

And add below code in your client context code.

 var dt = oListItem.get_item('datelistcolumnname');if (dt != null) { alert(moment(dt).format('L')); }
1
  • I want to get the date format of particular site, are you sure you are answering my question.
    – codemirror
    Commented Sep 20, 2017 at 16:37

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.