Java/Groovy - simple date reformatting
Your DateFormat
pattern does not match you input date String
. You could use
new SimpleDateFormat("dd-MMM-yyyy")
oldDate
is not in the format of the SimpleDateFormat
you are using to parse it.
Try this format: dd-MMM-yyyy
- It matches what you're trying to parse.
With Groovy, you don't need the includes, and can just do:
String oldDate = '04-DEC-2012'
Date date = Date.parse( 'dd-MMM-yyyy', oldDate )
String newDate = date.format( 'M-d-yyyy' )
println newDate
To print:
12-4-2012