見出し画像

SharePoint サイトのタイムゾーンを取得する方法

SharePoint サイトのタイムゾーンを確認するには、「サイトの設定」にアクセスする方法がありますが、もしあなたに「サイトの設定」にアクセスする権限がない場合は、 JavaScript を使って確認することができます。

JavaScript コードとその使い方

タイムゾーンを確認したい SharePoint Online サイトにアクセスし、そのサイトにあるなにかしらのリストにアクセスします。

そして、ブラウザの DevTools を開き、以下のスクリプトを実行します。

(async function(){
  let response = await fetch(
    _spPageContextInfo.webServerRelativeUrl + "/_api/web/RegionalSettings/TimeZone",
    {
      method: 'GET',
      headers: {
        'Accept': 'application/json;odata=verbose',
        'Content-Type': 'application/json;odata=verbose'
      },
      credentials: 'same-origin'
    }
  );
  if (!response.ok) {
    throw new Error('Network response was not ok ' + response.statusText);
  }
  let data = await response.json();
  console.log(data);
})();

すると以下のような値が返ってきます。

{
  "d": {
    "__metadata": {
      "id": "https://sample.sharepoint.com/sites/SampleSite/_api/web/RegionalSettings/TimeZone",
      "uri": "https://sample.sharepoint.com/sites/SampleSite/_api/web/RegionalSettings/TimeZone",
      "type": "SP.TimeZone"
    },
    "Description": "(UTC-08:00) 太平洋標準時 (米国およびカナダ)", // タイムゾーン
    "Id": 13,
    "Information": {
      "__metadata": {
        "type": "SP.TimeZoneInformation"
      },
      "Bias": 480, // 時差を分換算した値
      "DaylightBias": -60,
      "StandardBias": 0
    }
  }
}

この記事が気に入ったらサポートをしてみませんか?