Home > Back-end >  Groovy script to split date and time, and print it in format yyyyMMddHHmmssSSS
Groovy script to split date and time, and print it in format yyyyMMddHHmmssSSS

Time:12-21

From a Jenkins build it will return an output as Change sets: (1901) ----$ Kivi "comment about the update done" 17-Dez-2021 02:10 PM

I need to fetch only the date and time from this line 17-Sep-2020 02:15 PM and return an output in timezone format as yyyyMMddHHmmssSSS using Groovy. Have anyone tried with this ? Can someone provide some inputs regarding the same. Thank you !

CodePudding user response:

Let's say you have a string variable initialDate containing 17-Sep-2020 02:15 PM, you can do:

initialDate = '17-Sep-2020 02:15 PM'
date = new Date(initialDate).format('yyyyMMddHHmmssSSS')
println date // display 20200917141500000
  • Related