i have date value which comes from JIRA database (we are using -
In groovy script I store this date into a variable and wanted convert that into milliseconds to calculate further. The core is as follows. Please let me know what is the best way to do this.
def emailSendDate = (it.SEND_DATE)
def dt = new Date()
def dateObject = dt.parse("yyyy-MM-dd'T'HH:mm:ss", emailSendDate)
log.warn(dateObject)
Getting the error -
2021-03-16 12:45:02,579 ERROR [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingMethodException: No signature of method: java.util.Date.parse() is applicable for argument types: (String, java.sql.Timestamp) values: [yyyy-MM-dd'T'HH:mm:ss, 2021-03-15 11:53:24.0] Possible solutions: parse(java.lang.String), parse(java.lang.String, java.lang.String), parse(java.lang.String, java.lang.String, java.util.TimeZone), wait(), clone(), any() at Script2391$_run_closure4$_closure5$_closure6.doCall(Script2391.groovy:133) at Script2391$_run_closure4$_closure5.doCall(Script2391.groovy:124) at Script2391$_run_closure4.doCall(Script2391.groovy:102) at Script2391.run(Script2391.groovy:86)
Hi Nagappan,
You may want to try using the Simple Date Formatter to format the date instead of the Date.parse.
For example:-
import java.sql.Timestamp
import java.text.SimpleDateFormat
def originalDate = getFieldById(fieldChanged)
def originalDateValue = originalDate.value.toString()
def additionalDays = getFieldByName("Additional Days")
def additionalDaysValue = additionalDays.value as Double
def newDate = getFieldByName("New Date")
def days = 24 * 60 * 60 * 1000
if( originalDateValue != "" && originalDateValue.length()>0 && additionalDays.value != null) {
def oldDate = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(originalDateValue)
def additionalDaysNum = (new Double(additionalDaysValue)).longValue()
def ts = new Timestamp(oldDate.time).time
def updatedTimeStamp = new Timestamp(ts + additionalDaysNum * days).time
def updatedDate = new Date(updatedTimeStamp)
def formattedDate = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss zzz").format(updatedDate)
newDate.setFormValue(formattedDate)
}
Please note, this sample code is not 100% exact to your environment. Hence, you will need to modify it accordingly.
I hope this helps to solve your question. :)
Thank you and Kind Regards,
Ram
Thanks Ram. I was able to achieve with the below mentioned.
SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
String dateString = "23-03-2021 11:18:32"
Date date3 = sdf.parse(dateString);
log.warn ( date.getTime())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.