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: ᅡ 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에 대한 날짜 및 시간 패턴 섹션을 참조하십시오.