macking_liu
macking_liu

Reputation: 56

SimpleDateFormat("yyyyMMd‌dHH:mm:ss") has issue on groovy

I call groovy script in Jenkins pipeline.

def start_time = new Date()
def sdf = new SimpleDateFormat("yyyyMMd‌​dHH:mm:ss")
println sdf.format(start_time)

But I get "20160817‌​1708:34:35", the day has been output twice. So I test it on my local machine with groovy, and I get the same result.

Any thing I missed?

Upvotes: 2

Views: 12082

Answers (2)

Rao
Rao

Reputation: 21379

Michael is right, there is problem with the text provided in the question.

By the way, in groovy, one can directly format on the Date object without using SimpleDateFormat like below and does the same:

println new Date().format​('yyyyMMddHH:mm:ss')

Output

2016081711:04:17

Upvotes: 8

Michael Easter
Michael Easter

Reputation: 24468

I believe there are non-ASCII/Unicode characters in the format string. (They were clear when I pasted the code into Vim.) I have removed them and this works fine:

import java.text.*

def start_time = new Date()
def sdf = new SimpleDateFormat("yyyyMMddHH:mm:ss")
println sdf.format(start_time)

Upvotes: 8

Related Questions