Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get today's date in Groovy

Tags:

groovy

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.

like image 812
ErezN Avatar asked Jul 28 '15 16:07

ErezN


People also ask

How do I set the date in groovy?

public String format(String format, TimeZone tz)Create a String representation of this date according to the given format pattern and timezone. For example: def d = new Date(0) def tz = TimeZone. getTimeZone('GMT') println d. format('dd/MMM/yyyy', tz) would return the string "01/Jan/1970" .

How do I get yesterday's date on groovy?

Date previousDate = new Date() Date currentDate = new Date() previousDate. upto(currentDate) { it -> it-> represents date object. } currentDate. downto(previousDate) { it -> it-> represents date object. }


1 Answers

Then use:

new Date().format( 'yyyyMMdd' ) 
like image 94
Opal Avatar answered Sep 23 '22 10:09

Opal