Formatting a Date Using a Formatter
To format a datetime value datetimeVal to display only the hours and minutes in 24-hour format, you can do:
Date dv = datetimeVal as Date
def fmt = new Formatter(adf.context.locale)
def ret = (dv != null) ? fmt.format('%tH:%tM', dv, dv) : null
If the value of datetimeVal
were 2014-03-19 17:07:45
,
then this would produce a formatted string like:
17:07
To format a date value dateVal
to display the day of the week, month
name, the day, and the year, you can do:
Date dv = dateVal as Date
def fmt = new Formatter(adf.context.locale)
def ret = (dv != null) ? fmt.format('%tA, %tB %te, %tY',dv,dv,dv,dv) : null
If the value of dateVal
were 2014-03-19
, and the
current user's locale is US English, then this would produce a formatted string
like:
Wednesday, March 19, 2014