Search code examples
palantir-foundryfoundry-slate

what is best practice for retrieving the current time independent of user's system clock?


In a slate function we had been using javascript’s new Date() function to set a submission timestamp, however, this introduces dependency on the user’s system time. Are there any functions or libraries in slate that would pull a more objective timestamp?**


Solution

  • Maybe try to change the Javascript function from new Date() to new Date().toISOString(), it will update the date from the local time zone to the Coordinated Universal Time (UTC), so no matter where the users locate, the submission time will be the UTC timestamp.

    Also I found this article listed many useful date/time functions for Javascript, hope it helps: https://www.toptal.com/software/definitive-guide-to-datetime-manipulation