How to get current date format

Hi,

I used Plumsail form for SharePoint Online with the change Locale to “English (United Kingdom)” on Site Settings -> Region Settings.

When I set value on date field on form, It show value with format “dd/mm/yyyy”.

So, please show me how to get current date format by code.

Thanks

Hi!
You can find date and time format in the following JS-object:
Sys.CultureInfo.CurrentCulture.dateTimeFormat

Hi,

I have just used your suggest code (Sys.CultureInfo.CurrentCulture.dateTimeFormat). But it return for me still that is “M/d/yyyy”.

I placed your suggest code on JavaScript Editor on Plumsail Forms

Thanks.

You’re right, it seems that CurrentCulture contains settings of the current language, not regional settings.

You can retrieve the current locale id from the property below:
fd.field(‘DateTime’)._fieldSchema.LocaleId

And then transform it to date format using own mapping object.

Thank you so much.

But, how can I transform the Locale Id to date format (or culture name)?

Please give me the suggest code?

You should create a mapping object similar to this:

var dateFormats = {
    ...
    2052: "yyyy/M/d",
    2055: "dd.MM.yyyy",
    2057: "dd/MM/yyyy",
    2058: "dd/MM/yyyy",
    2060: "dd-MM-yy",
    2064: "dd.MM.yyyy",
    2067: "d/MM/yyyy",
    2068: "dd.MM.yyyy",
    ...
}

and get date format by Locale Id: dateFormats[localeId]. You can generate the complete list of available LCIDs and corresponding date formats with the code:

Thank you so much again.

Hi again,

Now, I can get LocaleId from DateTime column

I used this code to get LocaleId on javascript option:
fd.field(“DateColumn”)._fieldSchema.LocaleId;

I debugged that code. It show error for ._fieldSchema that is undefined.

Two week ago, I can get LocaleId by that code. But now it cannot.

Please help me.

Thanks

Dear @dat,
You might’ve noticed that the field itself was updated, the JS API has also slightly changed. Please, use either of these to get LocaleId:

fd.field("DateColumn")._lcid;
fd.spFormCtx.ListSchema.DateColumn.LocaleId;