Ask a Question

How to get the epoch time in the readyapi using the groovy scripts

Ayeshahyder
New Contributor

How to get the epoch time in the readyapi using the groovy scripts

Ayeshahyder_0-1683509759309.png

Unable to get the current time in milliseconds

3 REPLIES 3
Ayeshahyder
New Contributor

@TanyaYatskovska 

Can you please address this issue at the earliest. I would really appreciate your help.

ChrisAdams
Champion Level 2

Hi,

 

The below code segment works....

import java.util.concurrent.TimeUnit;

def epoch = System.currentTimeMillis();

log.info(epoch);  
log.info(epoch.toString());

 

Your example must be incomplete though.

 

The part I don't get is...

result["time"] = epoch.toString();

 

Extending the above to include this....

import java.util.concurrent.TimeUnit;

def epoch = System.currentTimeMillis();

log.info(epoch);
log.info(epoch.toString());

result["time"] = epoch.toString();

 

Running returns the following error....

Mon May 08 11:30:43 BST 2023:ERROR:An error occurred [No such property: result for class: Script6], see error log for details

 

Can you share more of your example or be clearer about what you want to achieve?

jjam
Contributor

long epoch = System.currentTimeMillis()/1000

cancel
Showing results for 
Search instead for 
Did you mean: