Home > javascript > getting Regional settings in Javascript from CSOM

getting Regional settings in Javascript from CSOM

March 26Hits:37
Advertisement

I am creating a custom data entry app in sharepoint using the CSOM. I need to update the default value of a datetime field, I can get the default value but the datetime is in UTC Format.

I need to convert it to whatever format the sharepoint server uses. I have tried using the SP.Web.RegionalSettings.get_Dateformat() method like so:

var context = SP.ClientContext.get_current(); regionalsettings = context.get_web().get_regionalSettings();   //global variable context.load(regionalsettings); context.executeQueryAsync(configLoaded, configFailed); ....  function configLoaded(){ var dateformat = regionalsettings.get_dateFormat(); 

but this just returns a 0 value every time

Answers

You can simply parse the date using Javascript Date object. If different cultures are being used, you have to get the culture being used and format it accordingly.

var date = oListItem.get_item('StartDate');
if(date) {
 date = new Date(date).format('MM/dd/yyyy');
 window.console && console.log(date);
}

//Update
var today = new Date();
oListItem.set_item('StartDate', today);
oListItem.update();

You could utilize CSOM TimeZone.UTCToLocalTime method to convert the specified date from Coordinated Universal Time (UTC) to local time.

Example

(function(){

  var context = SP.ClientContext.get_current();
  var web = context.get_web();
  var regionalSettings = web.get_regionalSettings();

  var dueDate = new Date();  //set DueDate to [now]
  var localDueDate = regionalSettings.get_timeZone().utcToLocalTime(dueDate);

  context.load(regionalSettings);
  context.executeQueryAsync(
     function() {

         console.log(localDueDate.get_value());
         //
     },
     function(sender,args){
         console.log(args.get_message());
     }
  );

})();

Related Articles

  • getting Regional settings in Javascript from CSOMMarch 26

    I am creating a custom data entry app in sharepoint using the CSOM. I need to update the default value of a datetime field, I can get the default value but the datetime is in UTC Format. I need to convert it to whatever format the sharepoint server u

  • How to detect user's Regional Settings with jQuery in Sharepoint 2010?

    How to detect user's Regional Settings with jQuery in Sharepoint 2010?August 20

    I want to detect with JavaScript or jQuery what are the Regional Settings of the current user in NewForm. This is want I want to get from user: --------------Solutions------------- try this one: var url = ctx.HttpRoot+"/_layouts/regionalsetng.aspx?Ty

  • Getting the Timezone in Regional setting using javascriptMay 12

    I want to get the timezone in SharePoint, which is set in the regional settings. To be specific it is set as Japan Time. I am using javascript to fetch the time, but unfortunately I can't. I tried this: var value = SP.RegionalSettings.get_timeZones (

  • Change regional settings through codingDecember 21

    How can we set the locale of a sharepoint site for a particular user according to his/her system locale through coding? Edit: Specifically, I've created a list through coding. Suppose that I've added an item to that list. Then I've changed the locale

  • Getting regional settings in app part?June 27

    I am creating an app part working with dates. I need to show date by users regional settings as well as in SharePoint. SharePoint Page have _spPageContextInfo.currentCultureName, where is current regional settings, but apppart has only url parameter

  • Mac: can I create custom region settings, copy, distribute and reuse it?August 8

    I'm a very finicky person when it comes to my locale settings, and none of the preset regions is good enough for me. I want my dates in german (or ISO) format, but I want the names of days and months to remain in english. I want 24h format, SI units,

  • Regional Settings in My SiteMay 5

    What is the difference between the below two steps to change the "Regional Settings" in My Site? Site Actions -> Site Settings -> Regional settings -> Locale My Settings -> My Regional Settings -> Locale (Uncheck the option "

  • sharepoint regional settings are differenet from server settingsOctober 4

    how to force sharepoint 2010 to use hosting server settings just as date and time i have problem in hijri date , sharepoint's date is different from server's date (hijri only) any ideas please ? --------------Solutions------------- Tried using Site S

  • Change regional settings on pre-Windows 2008 / VistaJanuary 14

    How do you change the regional settings of the various system accounts (local system, local service and network service) on older versions of Windows ? I can only find the page on MSDN that refers to this feature, but it's only applicable to Vista or

  • Start an application with specific regional settingsJuly 20

    I have to work with different applications which are, in my opinion, not wisely-coded; they require the user to use specific regional settings. For example, some applications I use require that the user have an MM/DD/YYYY date format, while others re

  • With German regional settings, how to display some cells in U.S.-currency-format e.g. $1,000.00?

    With German regional settings, how to display some cells in U.S.-currency-format e.g. $1,000.00?August 9

    My Windows 7 has regional settings set for German/Germany. This causes currency values in Excel to appear like this: 234.234,00 € However, sometimes I want currency data in a cell to appear like this: $234,234.00 No matter how I format the cell (see

  • DateTime value formatting with Regional Settings and CalendarTypeAugust 29

    I am trying to display the contents of date column in a different web part. I have not been able to get a string representation that takes into account the explicit "Calendar Type" available in the regional settings. I am able to get the value f

  • Use United States Regional Settings with dd/mm/yyy date formatJanuary 1

    On a current SharePoint site,wWe want to use en-US regional settings, changing only the date format to dd/mm/yyyy. Unfortunately, it seems impossible to change only that. I am sure that there is a way for changing the date formatting for the en-US lo

  • "Changed On/Modified" columns - Date Format & Regional SettingsFebruary 13

    I was wondering if I change my regional settings through: Site Settings - Regional Settings - Locale: Dutch (Netherlands), affects the date format of the standard columns (Changed On/Modified e.g.). I want the format to be 'dd-mm-yyyy'. Or should I w

  • English as a system language but Russian regional settingsApril 6

    I usually choose English as an installation language since I believe that the original is better than the translation. However, the environment I'm working in is mostly Russian, so I have to deal with locale specificity. Even worse is the fact that s

  • Synchronize user regional settings across site collectionsJune 6

    We have a company web application that is divided into multiple site collections though the average user only sees this as a single "website" because they are linked with a single global navigation. Some of the users are in branch offices with d

  • Is it possible to have non-English regional settings with English day/month names?

    Is it possible to have non-English regional settings with English day/month names?June 7

    I live in Estonia where most regional settings (number, currency and date formats) differ from those used in English-speaking countries. For instance, decimal symbol is comma, thousands separator is space, date format is day-month-year, etc. However,

  • Cannot edit regional settings in drupal 7July 22

    I cannot edit any of setting presented in regional settings category under admin/config/regional/settings. Whenever I for example remove tick from "Users may set their own time zone" and click save the page basically reloads with the same settin

  • Can the iPad support multiple Regional Settings simultaneously?August 23

    I need spell-checking in different languages such as English, German and Norwegian. I currently have only German spell-checking and it is quite irritating that it messes up with other languages' words. Is there some easy way of having spell-checking

  • SQQuery, Dates and Regional SettingsAugust 25

    First, some setup: My Site is set to Eastern Time, and the server is located in Eastern Time. I'm trying to run a query against a list using the created date. I have tried using all variations I can think of and just can't get the results I want. My

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.430 s.