Previous Topic: Using BeanShell Scripting LanguageNext Topic: Class Loader Sandbox Example


Using Date Utilities

The com.itko.util.DateUtils class includes a number of date utility functions as static methods. These functions all return the formatted date as a string. You can use these functions in parameter expressions or the Java Script step.

com.itko.util.DateUtils.formatDate(Date date, String format)
com.itko.util.DateUtils.formatCurrentDate(String format)
com.itko.util.DateUtils.formatCurrentDate(int offsetInSec, String format)
com.itko.util.DateUtils.rfc3339(Date date)
com.itko.util.DateUtils.rfc3339()
com.itko.util.DateUtils.rfc3339(int offsetInSec)
com.itko.util.DateUtils.samlDate(Date date)
com.itko.util.DateUtils.samlDate()
com.itko.util.DateUtils.samlDate(int offsetInSec)

For example, if you have a web service call that takes a formatted date string and the server is 2 minutes slow, you can use:

=com.itko.util.DateUtils.formatCurrentDate(-120,"yyyy-MM-dd'T'HH:mm:ss.SSSZ")

This generates the string "2007-11-22T13:30:37.545-0500", the current time minus 120 seconds formatted according to these guidelines.

RFC 3339 is slightly different from the date that the default Java date formatter generates. If you need a strict RFC 3339 date, you can use the rcf3339 functions:

=com.itko.util.DateUtils.rfc3339()

This generates the string "2007-11-22T13:30:37.545-05:00".

SAML dates are formatted using the format "yyyy-MM-dd'T'HH:mm:ss'Z'". The samlDate functions are simply helpers so you do not need to remember that format string when using the formatDate APIs.

For more information, see the following:

http://download.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html

http://tools.ietf.org/html/rfc3339#section-5.6