Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,467,408
Community Members
 
Community Events
177
Community Groups

Convert date into Milliseconds

i have date value which comes from JIRA database (we are using - 

  • v8.13.1)

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)

1 answer

1 accepted

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())

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS

Atlassian Community Events