12 Replies Latest reply on Dec 30, 2015 1:19 PM by Wicktor

    Get ( CurrentTimeUTCMilliseconds )


      Hello everyone,

      I need to write a script where a calculated text is showed only for very specific brief time that the user may choose from a list of options that would be one of the followings: 1/10 of sec, 1/25 of sec, 1/50 of sec, and 1/100 of sec.

      I tried to use the Get ( CurrentTimeUTCMilliseconds ) but I really can't manage how to use it.

      Anyone so kind may help ?

      Thank You,


        • 1. Re: Get ( CurrentTimeUTCMilliseconds )

          What do you wish to calculate? If you calculate

          GetAsTimeStamp ( Get ( CurrentTimeUTCMilliseconds ) / 1000 )

          the result will look something like:

          12-12-2015 17:39:00.150

          • 2. Re: Get ( CurrentTimeUTCMilliseconds )

            Thank you for your answer.

            Yes I used that from the FMP Help, but, would you mean that I should use the 3 digits on the right (in your example 150) as milliseconds count ?

            • 3. Re: Get ( CurrentTimeUTCMilliseconds )

              Yes that is the milliseconds, but if you use

              GetAsNumber ( Get ( CurrentTimeUTCMilliseconds ) )

              the full number is milliseconds ... only it is just a lot milliseconds, but if you do calculations with them it eassier

              • 4. Re: Get ( CurrentTimeUTCMilliseconds )

                Looks like you're better served with "pause/Resume Script [t]", you can use 1/50 as t without problems.

                • 5. Re: Get ( CurrentTimeUTCMilliseconds )

                  Hi siplus,

                  the "pause/Resume Script [t]" sounds very interesting.

                  You mean that a script like...

                  • Set Field [TimeSelected; "1 / 25"]
                  • Set Field [ShowTarget;  "123456"]
                  • Pause/Resume Script [Duration (seconds): TimeSelected]
                  • Set Field [ShowTarget;  ""]

                  will be accurate for displaying the target for 1/25 of a second (or any value for the TimeSelected field)

                  Is that so easy !? amazing !!!... and I was struggling with the Get ( CurrentTimeUTCMilliseconds ) function !!!!

                  Thank You !

                  • 6. Re: Get ( CurrentTimeUTCMilliseconds )

                    Hmmm... not so fast.... it all depends on your hardware, I guess.


                    Try the attached test I quickly assembled.


                    With the pause/resume script thing you can only go that far (Method 1).


                    Method 2 is better, but still hardware-dependent (mostly video card I guess).


                    Make sure you have no other FM windows opened (like Data viewer or Manage scripts).


                    Every time you hit the Show value buttons, look at the indication you get in the footer.




                    PS I tried with Method 3, using Hide when instead of Method 2's conditional formatting, but there's no difference, maybe a bit slower.

                    • 7. Re: Get ( CurrentTimeUTCMilliseconds )

                      Hello siplus,

                      Very nice !

                      Method 1 shows a slower timing compared to selected timing (for example selecting 1/25 gives me around 72 msecs +/- 4 msecs).

                      Method 2 and 3 are pretty consistent with a difference of only 1 or 2 msecs and both works fine on my MacBookPro 17" (Mid 2010) giving correct timing (for example selecting 1/25 gives me a consistent response of 40-42 msecs, which is just perfect since 2 msecs are really not an issue).

                      I tested your file also on iMac 21" (Middle 2013) and Method 1 gives quite different results but Method 2 and 3 are very consistent with the above results obtained on MacBookPro.


                      I have no idea how much Method 2 or 3 would be hardware-dependant on different computers (Macs or PCs), maybe not so much ?

                      Or maybe the GetAsNumber ( Get ( CurrentTimeUTCMilliseconds ) ) would be less hardware-dependant since it measure real time?

                      Thank You for your efforts :-)

                      • 8. Re: Get ( CurrentTimeUTCMilliseconds )

                        Any further calc you add, like getAsNumber(), will interfere - when even slightly - with the precision. It's not necessary, as the function result you're evaluating already outputs a numeric value.


                        Conditional formatting is influenced by the position of the element on the layout: elements in the back are evaluated and rendered before those in front, but that only matters seriously when you have hundreds of layout elements. However, a further test would be to isolate each method on its own layout with nothing else around. Even deleting header and footer can help, especially if your solution is used in a client-server environment.

                        • 9. Re: Get ( CurrentTimeUTCMilliseconds )

                          In order to demonstrate that method 2 is slightly faster than method 3, you can do the following:


                          - add 1/200 to the value list and select it.


                          - from the conditional formatting of the gValue field in Method 2, remove the color, leave just the setting of the font size to 500.


                          - change in both scripts (DisplayValue2 and DisplayValue3) the 4th line (for precision) to

                          Set Variable [ $stopover ; Value: 1000 * Evaluate($fraction) - 1 ]




                          On my MacBookPro 15" retina, late 2013, I was able to get 7 msec with method 2 say every 7 clicks of the button.


                          Method 3 never achieved 7 ms, only 8, sometimes. Really pushing it

                          • 10. Re: Get ( CurrentTimeUTCMilliseconds )

                            I did and I confirm what you said

                            I am already implementing suggestions from your example file (using Method 2) into my solution (getting a bit busy since there are some 50 options to choose from (random generated numbers and letters, standardized  testing target, and also shapes).

                            Your help was very useful to me.

                            Thank You again for your time and efforts,


                            • 11. Re: Get ( CurrentTimeUTCMilliseconds )

                              don't tell me you're in ophthalmology

                              • 12. Re: Get ( CurrentTimeUTCMilliseconds )

                                Optometry !