How to get unique values for `time.Now` when called twice in Windows

Hello.

We have a test where we call time.Now twice. On Windows it fails because it returns the same time. In other systems it works fine.

I have looked for information on how to solve this problem and how to get a unique time but without good results.

Do you have an idea how to achieve this?

Wait longer between those snapshots.

Windows does clock has only a millisecond resolution if I recall correctly.

I believe this is correct: https://docs.microsoft.com/en-us/windows-server/networking/windows-time-service/support-boundary#windows-10-and-windows-server-2016

What does your test do that requires the times be different? Could you check if you’re on windows and sleep for 1ms to make sure your second call to time.Now gets a new time?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.