new Date(Date.now()).toLocaleTimeString("en-US", {
timeZone: "America/Chicago",
})
The above code outputs something like: 4:30:05 PM
.
For me, this comes in handy when running a Node server that is being watched by something like nodemon
. In this way, I can see ๐ the timings and know that things are updating properly as I save my code.
Note that if you want the entire date included, just use: toLocaleString
instead of toLocaleTimeString
๐๐พ.
Finally, you can see ๐ the list here to get the correct TZ strings such as "America/Chicago"
.
Top comments (3)
You should rather use Intl instead
That works too...not really sure what would be the benefit.
developer.mozilla.org/en-US/docs/W...
Intl is the new optimized API where Date objects starts to be a little obsolete.