Forum Discussion

rajareddytester's avatar
rajareddytester
Occasional Contributor
13 years ago

How to find the TimeTaken using Groovy Script

Hi,

Can Any one suggest me how to Calculate the "Time Taken" using Groovy Script?

I have used two separate groovy scripts for calculating Start Time and End Time, and is printed to an Excel Sheet.

Time format used : YYYY:MM:DD HH:MM:SS:SSS

OR

Please suggest me how to get the value of a variable from one script and to use it in another script


Possibly give me the elaberative code to fetch the value from one script to another script.

Very urgent suggest me as soon as possible please.

Thanks,
Raja Reddy
  • Aaronliu's avatar
    Aaronliu
    Frequent Contributor
    not sure what's your test scenario? here show a simple example to you:

    import java.text.SimpleDateFormat

    String str = "2019-10-18"
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd")
    Date d = df.parse(str)
    Calendar cal = new GregorianCalendar()
    cal.setTime(d)
    cal.add(Calendar.YEAR,-2)
    def a = cal.getTime()
    def c = a.format("yyyy-MM-dd")
    log.info c