GlideDateTime フィールド値の変更
この例では、サーバーサイドスクリプトを使用して GlideDateTime フィールド値を変更する方法を示します。
GlideDateTime フィールドまたはスクリプトオブジェクトを指定して、値を簡単に変更するさまざまな方法を示します。同じ概念が GlideDate オブジェクトにも適用されます。
注:
次のスクリプトは、グローバルアプリケーションのみを対象としています。
//You first need a GlideDateTime object
//this can be from instantiating a new object "var gdt = new GlideDateTime()"
//or getting the object from a GlideDateTime field
//getting the field value (for example: var gdt = current.start_date) only returns the string value, not the object
//to get the object use var gdt = current.start_date.getGlideObject();
//now gdt is a GlideDateTime object
var gdt = current.start_date.getGlideObject();
//All methods can use negative values to subtract intervals
//add 1 hour (60 mins * 60 secs)
gdt.addSeconds(3600);
//add 1 day
gdt.addDaysLocalTime(1);
//subtract 1 day
gdt.addDaysLocalTime(-1);
//add 3 weeks
gdt.addWeeksLocalTime(3);
//subtract 6 months
gdt.addMonthsLocalTime(-6);
//add 1 year, representing the date and time using the UTC timezone instead of the local user's timezone.
gdt.addYearsUTC(1);
//set the value of the GlideDateTime object to the current session timezone/format
GlideSession.get().setTimeZoneName('US/Eastern');
gdt.setDisplayValue('2018-2-28 00:00:00');
gs.info('In ' + GlideSession.get().getTimeZoneName() + ": " + gdt.getDisplayValue());
一般的な日付と時刻の形式の競合
誤った日時形式の文字列を指定すると、GlideDate、GlideDateTime、および GlideTime API のメソッドで予期しない動作が発生する可能性があります。次の表を使用して、形式の問題を解決してください。
| 形式が正しくありません | 説明 | 正しい形式 |
|---|---|---|
| YYYY-MM-dd HH:mm:ss |
|
yyyy-MM-dd hh:mm:ss |
| HH:mm:ss a Hh:mm:ss |
|
hh:mm:ss:a HH:mm:ss |
| HH:mm:ss z |
|
HH:mm:ss zzzz |
| MM-dd-yyyy HH:MM |
|
MM-dd-yyyy HH:mm |
| yyyy-DDD-MM |
|
yyyy-MM-dd |
詳細については、 SimpleDateFormat の「日付と時刻のパターン」セクションを参照してください。