Forum Discussion

Ayeshahyder's avatar
Ayeshahyder
New Contributor
12 months ago

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

Unable to get the current time in milliseconds

3 Replies

  • ChrisAdams's avatar
    ChrisAdams
    Champion Level 3

    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?