Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Obtaining milliseconds from -now()-

    According to the documentation:

    tc = now()

    where

    tc: number of milliseconds from 01jan1960 00:00:00.000, unadjusted for leap seconds [emphasis added]
    Yet, in practice (see below), it seems to be truncated to the nearest second.

    .ÿ
    .ÿversionÿ17.0

    .ÿ
    .ÿclearÿ*

    .ÿ
    .ÿlocalÿline_sizeÿ`c(linesize)'

    .ÿsetÿlinesizeÿ80

    .ÿ
    .ÿmata:
    -------------------------------------------------ÿmataÿ(typeÿendÿtoÿexit)ÿ------
    :ÿmataÿsetÿmatastrictÿon

    :ÿ
    :ÿvoidÿfunctionÿMS()ÿ{
    >ÿ
    >ÿÿÿÿÿÿÿÿÿrealÿscalarÿnow,ÿthen
    >ÿ
    >ÿÿÿÿÿÿÿÿÿthenÿ=ÿnow()
    >ÿÿÿÿÿÿÿÿÿstata("sleepÿ250")
    >ÿÿÿÿÿÿÿÿÿnowÿ=ÿnow()
    >ÿ
    >ÿÿÿÿÿÿÿÿÿassert(nowÿ==ÿthen)
    >ÿ
    >ÿÿÿÿÿÿÿÿÿrealÿscalarÿindex
    >ÿÿÿÿÿÿÿÿÿforÿ(index=1;ÿindex<=2;ÿindex++)ÿ{
    >ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿprintf("%tcHH:MM:SS.sss\n",ÿ(now,ÿthen)[index])
    >ÿÿÿÿÿÿÿÿÿ}
    >ÿ}

    :ÿ
    :ÿMS()
    20:47:40.000
    20:47:40.000

    :ÿ
    :ÿprintf("%3.0f\n",ÿclockpart(clock("00:00:00.125",ÿ"hms"),ÿ"ms"))
    125

    :ÿ
    :ÿprintf("%3.0f\n",ÿclockpart(now(),ÿ"ms"))
    ÿÿ0

    :ÿ
    :ÿend
    --------------------------------------------------------------------------------

    .ÿ
    .ÿsetÿlinesizeÿ`line_size'

    .ÿ
    .ÿexit

    endÿofÿdo-file


    .


    Is there any way to obtain full-precision clock time from the Mata function now(), or by any other way in Stata short of resorting to Python or Java?

    Environment: Windows 10 Pro, 64-bit, current update
    Attached Files

  • #2
    Thank you Joseph Coveney for drawing our attention to this. It is indeed a bug in function now() and it will be fixed in a future update.

    -- Kreshna

    Comment


    • #3
      Originally posted by Kreshna Gopal (StataCorp) View Post
      it will be fixed in a future update.

      -- Kreshna
      OK, thank you, Kreshna. I'll await the update.

      Comment


      • #4
        I see from the most recent update:

        29. Stata function now() and Mata function now() previously returned the current e_tc datetime precise to the nearest second. It is now precise to the nearest millisecond.
        Thank you.

        Comment

        Working...
        X