Forum Discussion

TestQA1's avatar
TestQA1
Frequent Contributor
2 years ago

Getting milliseonds with Time() method

Hi,

 

I have a time like this = 2023-09-06 14:21:18.630 where '630' is ms

 

when I use aqConvert.DateTimeToFormatStr(aqDateTime.Time(), "%H:%M:%S") it only gets current time upto seconds.

Is there any way I can also get milliseconds which limits to 3 digits like in the example above?

I'm using javascript.

Thanks

  • You can get current time like so,

    function Timestamp()
    {
        var d = Date.now()
        Log.Message(d);
    }

    this will return an Epoch time. E.g. 1694011583707 is 6 September 2023 14:46:23.707

     

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    You can get current time like so,

    function Timestamp()
    {
        var d = Date.now()
        Log.Message(d);
    }

    this will return an Epoch time. E.g. 1694011583707 is 6 September 2023 14:46:23.707

     

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Here's an example,

    function Timestamp()
    {
        var d = new Date("2023-09-06 14:21:18.630");
        var s = d.getSeconds();
        var ms = d.getMilliseconds();
        Log.Message(s); 
        Log.Message(ms);
    }
    • TestQA1's avatar
      TestQA1
      Frequent Contributor

      Thanks rraghvani but I need to get the current time with milliseconds like this '2023-09-06 14:21:18.630'. I cannot define the time that's the problem. So is it possible to use Time() method to also provide ms?