Twine uses pure javascript and then a layer of 'twinescript' on top of that. It depends how deep you wanna go!
If you just want to make your own simple function like time, sticking to Twine language, you'd most likely create a "widget" - look up how to do this on the web! But basically it's a way of wrapping up a number of twine functions in one that you could then call at any point you wanted.
Or if you knew Javascript and wanted to go
really deep, you could write your own functions in pure Javascript and then wrap those in 'Macros' which - as far as I understand it - are similar to widgets but ... yeah. Like i said, are just javascript. Again, there's a bunch of documentation online and advice also depends on what version you're using (Harlowe? Sugarcube?) ...
The twinery.org forums are pretty useful, there's an active subreddit at r/twinegames and I'd also recommend searching on YouTube too.
Oh, and for a couple of repositories for pre-made functions that can take your twine game up a notch, these are both really good too:
You must be registered to see the links
You must be registered to see the links
They might also be useful for analyzing the source code to work out how they're doing what they're doing - as it sounds from your question like you already have some programming knowledge? Anyway, there's tons of info out there to help you find what you need. Good luck!