Reputation: 699
I am trying to get today's date in format of yyyyMMdd
in groovy language.
I have tried to do this:
String oldDate = '20150702'
Date date = Date.parse( 'yyyyMMdd', oldDate )
String currentDate = date.format( 'yyyyMMdd' )
Output: 20150702
I am trying to get today's date however.
Upvotes: 34
Views: 104132
Reputation: 14803
The answer of @Opal did not work for me:
groovy.lang.MissingMethodException: No signature of method: java.util.Date.format() is applicable for argument types: (String) values: [yyyy-MM-dd]
Here is a solution that worked for me:
new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date())
(edit: removed extra parenth at the end of snippet)
Upvotes: 9