Your solution is probably the clearest pattern. I was thinking about the toISOString and having an ability to pull out whole patterns, the problem is that is doesn't take into account the timezone offset.
toISOString
Maybe something like this ...
const getDateStandard= () => { const d = new Date(); let local = new Date(d); local.setMinutes(d.getMinutes() - d.getTimezoneOffset()); const s_iso = local.toISOString(); const date = s_iso.substring(0,10); const time = s_iso.substring(11,16); const dow = local.toDateString().substring(0, 3); return `[${date} ${dow} ${time}]`; }; console.log(getDateStandard());
That's a great one if one wants to timestamp in UTC time, or another timezone. Thanks!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Your solution is probably the clearest pattern. I was thinking about the
toISOString
and having an ability to pull out whole patterns, the problem is that is doesn't take into account the timezone offset.Maybe something like this ...
That's a great one if one wants to timestamp in UTC time, or another timezone.
Thanks!