Get Current time in Milliseconds

VirtEyesVirtEyes Posts: 62

I am trying to generate a timestamp of the current time but in milliseconds. Is there a scripting option to do this, perhaps Extension tool, or is it possible to generate it via the Data Generator Tool?


  • Thomas MooreThomas Moore Posts: 82 admin

    This is possible in the Data Generator Tool, you will want to use a syntax like the following:

    HH:mm:ss.SSS or hh:mm:ss.SSS a
    This will give you a time stamp like
    13:30:00.010 or 01:30:00.010 PM, respectively.

    Hope this helps!

  • VirtEyesVirtEyes Posts: 62
    edited November 2019

    Hey Thomas, will this generate the timestamp as just the number of milliseconds?
    Ex: 12 pm -> 12333434 milliseconds

  • VirtEyesVirtEyes Posts: 62

    We have a script that does this but I haven't adjusted yet to Virtualize, additionally, I want to see if I could use the Data Generator Tool instead:

    import java.util.GregorianCalendar;
    GregorianCalendar cal = new GregorianCalendar();
    responsedate = cal.getTimeInMillis();

    testExec.setStateObject("responsedate", responsedate);

  • Thomas MooreThomas Moore Posts: 82 admin

    I think in that case I missed your question :) It looks like this should be handled in an extension tool.

    If you want to do this in Javascript, then I would use the following:
    var d = new Date("<Today's Date>");
    var n = d.getMilliseconds();

    More info on this here:

  • VirtEyesVirtEyes Posts: 62

    Hey Thomas, that resource works however it returns a three digit number

    I dug around and produced this Groovy script which works:

    import com.parasoft.api.*

    public int getMili(){
    Calendar responsedate = Calendar.getInstance();

    return responsedate.getTimeInMillis() / 1000;


  • benken_parasoftbenken_parasoft Posts: 1,004 ✭✭✭

    Folks, just use java.lang.System.currentTimeMillis()

Sign In or Register to comment.