Date Formatting in JavaScript (and OptoScript)

On the Optoscript example, one word of caution is to not use the GetYear, GetMonth, GetDay, etc functions together since time functions are nondeterministic. For instance, the call to GetHours() could happen at 11:59, then the call to GetMinutes() could be at 12:00. Those functions are fine if you just need the month or the year, etc, but they shouldn’t be used in combination.

Instead, use the GetDateTime method that returns all the above values into an integer table and then use the values out of the table.

See Mary’s example and comments on Convert Integer 32 to Timestamp String - #2 by mstjohn for the proper way to do this.

1 Like