Ka Li
Ka Li

Reputation: 41

Groovy String and datestamp

I am new to Groovy and wonder following is possible?

I have a file generated automatically with datestamp, example saledata20180429 Is it possible to code this with Groovy and convert the filename to saledata-2018-04-29.txt

Upvotes: 2

Views: 52

Answers (1)

ernest_k
ernest_k

Reputation: 45319

Simple substring calls can get that done:

def name = 'saledata20180429'
def newname = "saledata-${name[8..11]}-${name[12..13]}-${name[14..15]}.txt"

newname evaluates to 'saledata-2018-04-29.txt'

Upvotes: 1

Related Questions