dat
August 16, 2018, 9:30am
#1
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
jusper
August 16, 2018, 1:43pm
#2
Hi!
You can find date and time format in the following JS-object:
Sys.CultureInfo.CurrentCulture.dateTimeFormat
dat
August 17, 2018, 2:08am
#3
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.
jusper
August 17, 2018, 5:46am
#4
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.
dat
August 20, 2018, 7:21am
#5
Thank you so much.
But, how can I transform the Locale Id to date format (or culture name)?
Please give me the suggest code?
jusper
August 20, 2018, 3:10pm
#6
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:
dat
September 11, 2018, 4:14am
#8
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;