Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Time stamp.... Is there a best way?

November 26 (11 years ago)
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Time stamp.... Is there a best way?

I have been working on creating handouts on the fly for table results.... but it would be easy to forget when the handout was last created or just created.

Anyone have any thoughts on placing a time stamp?

From the little investigating I have been doing (which is very little) javascript seems to be picky about this?

Any suggestions?
November 27 (11 years ago)
Lithl
Pro
Sheet Author
API Scripter

What do you mean by "picky"?

var now = new Date();

var date = now.toDateString(); // Tue Nov 26 2013
var iso = now.toISOString(); // 2013-11-27T01:41:03.900Z
var json = now.toJSON(); // 2013-11-27T01:41:03.900Z
var lDate = now.toLocaleDateString(); // Tuesday, November 26, 2013
var lTime = now.toLocaleTimeString(); // 7:41:03 PM
var locale = now.toLocaleString(); // Tuesday, November 26, 2013 7:41:03 PM
var dStr = now.toString(); // Tue Nov 26 2013 19:41:03 GMT-0600 (Central Standard Time)
var time = now.toTimeString(); // 19:41:03 GMT-0600 (Central Standard Time)
var utc = now.toUTCString(); // Wed, 27 Nov 2013 01:41:03 GMT
If those formats don't do it for you, the Date object also has methods to get the year/month/day/hour/minute/second/millisecond (with UTC versions of each), so you can build your own output format.
November 27 (11 years ago)
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
I guess where I was confused is the javascript is actually processed for API on the server side of things and not the client side of things.

How I was thinking to apply this was to keep track of when an API was last used for within a play session i.e. ....

* Never run this session
* Ran 15 minutes ago
November 27 (11 years ago)
The API scripts run server-side, that's why you don't have access to the browser's DOM and can't log to the browser's console. I can't say how accurate time keeping would be, Roll20 probably runs across a number of nodes each with their own local time, but they're probably close enough for most purposes.

If you need per-session time tracking, just use a variable that gets initialized at the start of the session - easily, though perhaps inaccuracy defined by when the sandbox restarts. If you need it a bit more persistent across sandbox restarts, you could store it in the state.