Groovy - Convert date string to formatted date

OK, I'm trying to convert a date string from a format, for example:

2014-01-21 00:00:00

to

01/21/2014

I tried many variations and I crumbled and burned. The problem is that for testing, I have to create a script, export it in the process to Bonita (BPM software), import it, and then create several cases. It will take a lot of time.

Hope someone knows how to do this.

Also, is there a simple groovy editor out there? This will help me learn to write groovy very quickly.

+4
source share
2 answers

Groovy Dates are methods parseand formatfor conversion to and from strings in different formats:

def format1 = '2014-01-21 00:00:00'
def format2 = Date.parse("yyyy-MM-dd hh:mm:ss", format1).format("dd/MM/yyyy")
assert format2 == '01/21/2014'

Java SimpleDateFormat.

+9
String olddate='2014/01/21 00:00:00'
Date date = Date.parse("yyyy/MM/dd HH:mm:ss",olddate)
String newDate = date.format( 'MM/dd/yyyy' )
log.info newDate
+2

All Articles