Reputation: 56
I call groovy script in Jenkins pipeline.
def start_time = new Date()
def sdf = new SimpleDateFormat("yyyyMMddHH:mm:ss")
println sdf.format(start_time)
But I get "201608171708: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
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
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