You can not remove timezone information when creating Date
object -- this is a deficiency of the API.
The dates created via various Date
APIs are parsed according to provided timezone (if the given method supports it), or if missing, they assume your local machine's timezone; then internally they're represented as dates relative to the UTC timezone.
Whenever you stringify a date, you implicitly invoke date.toJSON()
which in turn invokes date.toISOString()
, which stringifies to UTC-relative time (hence Z
as the end which stands for Zulu
i.e. UTC).
As far as I can tell there's no method that serializes to ISO-like string but using local timezone.
You could use low-level Date properties to write your own method which serializes back to the local timezone if you really need to, or you could use a library like date-fns
. You could use moment
library, but while very powerful, it's huge so be careful with it.