GlideDateTime - setDisplayValue(String dateTime, String format)

Sets a date and time value using the current user's time zone and the specified date and time format.

This method throws a runtime exception if the date and time format used in the dateTime parameter does not match the format parameter. You can retrieve the error message by calling getErrorMsg() on the GlideDateTime object after the exception is caught.

Table 1. Parameters
Name Type Description
dateTime String The date and time in the current user's time zone.
format String The format to use to parse the dateTime parameter.
Table 2. Returns
Type Description
void

Scoped equivalent

To use the setDisplayValue() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - setDisplayValue(String value, String format).

var gdt = new GlideDateTime("2011-02-02 12:00:00");
gdt.setDisplayValue("20-5-2011 12:00:00", "dd-MM-yyyy HH:mm:ss");
gs.print(gdt.getValue());

Output:

2011-05-20 19:00:00