I want to use the Harlowe (current-time:) macro to display the time, but it shows times like 5:09 AM as "5:9 AM." How do I add that leading zero back in? And is there any way to include the seconds as well? I tried making a clock in Javascript, but a clock that works in my HTML file doesn't work in a Twine file (supposedly because the stylesheet isn't at the end of the document, according to the internet.)
Comments
You can create your own currentTime function with the features you want.
warning: The following uses a Javascript substr function with a negative start index which may not be supported by all web-browser so you may want to add the following Javascript Polyfill (from the above MDN link) to the start of your Story Javascript area. The Story Javascript area is access via the Edit Story Javascript menu item.
The following Javascript code creates a My.currentTime() function which returns the current time (hours:minutes:seconds), with both the minutes and seconds being zero padded as needed. The function is contained within a namespace named My so that the function does not interfere with Harlowe's or the web-browser's code, you can change the name of the namespace to whatever you prefer by just changing all occurrences of My.
The code needs to be placed within the Story Javascript area (after the above Polyfill if you also added it)
You use a (print:) macro like the following to display the current time in a passage:
The Story Javascript area is accessed via the Edit Story Javascript menu item.
I had to modify the currentTime function to the following: ... because I incorrectly assumed that the original Harlowe 12-hour am/pm related code was valid but it displays One minute past midday/midnight as 0:01 when it should be 12:01.