Date operations - script to Java migration
For the Date operations, not all of the script operations from the Script API are implemented in the Java™ API. Alternative Java code is provided for those script operations that are not implemented in the Java API.
| Script operation | Alternative Java code |
|---|---|
| today () | new java.util.Date(); |
| new Date() | java.text.SimpleDateFormat sdfFormat = new java.text.SimpleDateFormat(sFormat,locale); sdfFormat.parse(sDate); |
| isDateBefore() | java.util.Date.before(sSecondDate); |
| isDateAfter() | Java.util.Date.after(sSecondDate); |
| formatDate() | com.ibm.icu.text.SimpleDateFormat |
| parseDate() | com.ibm.icu.text SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, locale); Date date = dateFormat.parse(stringDate, new ParsePosition(0); |
| addDate | Calender cal = java.util.Calender.getInstance(); Cal.setTime(date); Cal.add(Calender.YEAR, value); |
| getDateField | java.util.Calender.set(); |
| setDateField | java.util.Calender.set(); |
| getTime | new Integer((int)(date.getTime()/1000)); |
| getDateTimeInUserTimeZone | User.getTimeZoneOffset After obtaining the time zone offset, you need to convert the int obtained to hh:mm format, and use TimeZone.getTimeZone(“GMT+5:30”). Use the Calendar object to convert time to the server's TimeZone. |