Parsing January 31, 2000, i.e. 1000131 to be formatted to 20000131.
1 - Century
00 - Year 2000
01 - January
31 - Day
The example uses joda-time which can be downloaded from this link: http://www.joda.org/joda-time/
import org.joda.time.format.DateTimeFormat
String date = 1000131;
if(date.length() > 6)
{
(DateTimeFormat.forPattern("yyyyMMdd").print(DateTimeFormat.forPattern("CyyMMdd").parseLocalDate(date)))
}
else
{
(Date.parse( 'yyMMdd', date)).format( 'yyyyMMdd' )
}
No comments:
Post a Comment