LoginSignup
2
0

More than 3 years have passed since last update.

ServiceNowでUTCとの時差を取得する

Last updated at Posted at 2020-12-22

Version: Paris

ServiceNowのDate, Date/Time型

ServiceNowのDate/Time型ではDB内でUTC(GMT)のUNIXTIME(エポック秒)でミリ秒まで保持していて利用しているユーザーのTimezoneに従って計算して表示されているようです

[Date and Date/Time fields]
https://docs.servicenow.com/bundle/paris-platform-administration/page/administer/time/reference/r_UseDateAndTimeFields.html
image.png
[Time configuration]
https://docs.servicenow.com/bundle/paris-platform-administration/page/administer/core-configuration/concept/p_Time.html
image.png
とても便利な仕組みだと思いますがちょっと任意のTimezoneの値を取得したくなったので調べてみました

Packages.java.util.TimeZoneを使う

色々ググった結果この方法が見つかりました(関数にしています)

prt_tz_ofs("Asia/Tokyo");
prt_tz_ofs("US/Pacific");
prt_tz_ofs("Australia/Eucla");

function prt_tz_ofs(p_tz) {
  var gdt = new GlideDateTime();
  var tz = Packages.java.util.TimeZone.getTimeZone(p_tz);
  gdt.setTZ(tz);
  var tzoffs = gdt.getTZOffset() /1000/ 60/60;
  gs.info(p_tz + " ha " + tzoffs + " hours!!");
}

Scripts - Backgroundで実行した結果が以下です
image.png

もうちょっと便利な方法があるかもですがやりたいことは出来ました

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0