spacer
Skip to content

@pnp/sp/regional-settings

The regional settings module helps with managing dates and times across various timezones.

IRegionalSettings

Invokable Banner Selective Imports Banner

Scenario Import Statement
Selective 1 import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import { IRegionalSettings, ITimeZone, ITimeZones, RegionalSettings, TimeZone, TimeZones, } from "@pnp/sp/regional-settings";
Selective 2 import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/regional-settings";
Selective 3 import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/regional-settings/web";
Preset: All import { sp, Webs, IWebs } from "@pnp/sp/presets/all";
import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/regional-settings/web";

// get all the web's regional settings
const s = await sp.web.regionalSettings();

// select only some settings to return
const s2 = await sp.web.regionalSettings.select("DecimalSeparator", "ListSeparator", "IsUIRightToLeft")();

Installed Languages

You can get a list of the installed languages in the web.

import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/regional-settings/web";

const s = await sp.web.regionalSettings.getInstalledLanguages();

The installedLanguages property accessor is deprecated after 2.0.4 in favor of getInstalledLanguages and will be removed in future versions.

TimeZones

You can also get information about the selected timezone in the web and all of the defined timezones.

import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/regional-settings/web";

// get the web's configured timezone
const s = await sp.web.regionalSettings.timeZone();

// select just the Description and Id
const s2 = await sp.web.regionalSettings.timeZone.select("Description", "Id")();

// get all the timezones
const s3 = await sp.web.regionalSettings.timeZones();

// get a specific timezone by id
// list of ids: https://msdn.microsoft.com/en-us/library/office/jj247008.aspx
const s4 = await sp.web.regionalSettings.timeZones.getById(23);
const s5 = await s.localTimeToUTC(new Date());

// convert a given date from web's local time to UTC time
const s6 = await sp.web.regionalSettings.timeZone.localTimeToUTC(new Date());

// convert a given date from UTC time to web's local time
const s6 = await sp.web.regionalSettings.timeZone.utcToLocalTime(new Date())
const s7 = await sp.web.regionalSettings.timeZone.utcToLocalTime(new Date(2019, 6, 10, 10, 0, 0, 0))

Title and Description Resources

Added in 2.0.4

Some objects allow you to read language specific title information as shown in the following sample. This applies to Web, List, Field, Content Type, and User Custom Actions.

import { sp } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/regional-settings";

//
// The below methods appears on
// - Web
// - List
// - Field
// - ContentType
// - User Custom Action
//
// after you import @pnp/sp/regional-settings
//
// you can also import just parts of the regional settings:
// import "@pnp/sp/regional-settings/web";
// import "@pnp/sp/regional-settings/list";
// import "@pnp/sp/regional-settings/content-type";
// import "@pnp/sp/regional-settings/field";
// import "@pnp/sp/regional-settings/user-custom-actions";


const title = await sp.web.titleResource("en-us");
const title2 = await sp.web.titleResource("de-de");

const description = await sp.web.descriptionResource("en-us");
const description2 = await sp.web.descriptionResource("de-de");

You can only read the values through the REST API, not set the value.