def formatSqlDate = { attrs ->
def String startdatetime = "${attrs['targetDate']}"
def DateFormat odf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.S");
def DateFormat df = new SimpleDateFormat( "MMM d, ''yy" );
out << df.format(odf.parse(startdatetime))
}
Then I can simple reference it with:<g:formatsqldate targetdate="${domain.dateObject}">
A person can mode the date format string all they want and also could put in various cases or a flag to select a format style if they wished.
4 comments:
nice one thanks was pretty useful for me!
Seems sql.date inherits from util.date so wondering why theres a need to convert to string and reconvert, rather than format the sql date object directly....
Sanj,
It does seem odd.. I did find one could do this. Say you have an sqlDate object, then:
long milliseconds = sqlDate.getTime() + (sqlDate.getNanos() /1000000)
def theDate = new Date(milliseconds)
or all on one line of course if you wish too . :)
mind the targetDate vs targetdate
this caused me some head scratching
Post a Comment