datepicker date off by one day

前端 未结 14 944
攒了一身酷
攒了一身酷 2020-12-01 05:22

The date returned by date picker is off by one day. Is it a problem in my code or is it a bug?

The date sent to date_picker is 2012-03-21. The date returned by dat

14条回答
  •  爱一瞬间的悲伤
    2020-12-01 05:37

    This is not a bug, but definitely confusing.

    Most of the answers on this page are confused and contain some mis-information.

    The real issue is in how the javascript Date object parses date strings.

    The best answer I have found is this stack-O answer. Check out its' excellent write-up.

    Below is a very pertinent comment from the answer mentioned above. (credit: @Mizstik)

    All of this is due to the behavior of the underlying Date.parse() trying to follow ISO 8601. When the date string follows the yyyy-mm-dd format, it's assumed to be ISO 8601 with implicit UTC 00:00. When the string deviates from the format (e.g. mm-dd-yyyy or slash instead of hyphen), it falls back to the looser parser according to RFC 2822 which uses local time when the timezone is absent. Admittedly, this will all be quite arcane to an average person.

提交回复
热议问题