getDay() return wrong day if day is with leading zero [duplicate]

你说的曾经没有我的故事 提交于 2021-02-19 03:44:09

问题


I am facing this issue with javascript, I get yyyy-mm-dd dates from a database, but when I want to get the number of the week with getDay(), I get a wrong number if the day is with leading zero


I wrote a posible solution to parse MySql date into Javascript Date

function parseDate(str){
  var dt=str.replace(/[-T:]/g," ").split(" ");
  return new Date(dt[0],dt[1]-1,dt[2],dt[3]|0,dt[4]|0,dt[5]|0);
}

parseDate("2018-02-08");
//Thu Feb 08 2018 00:00:00 GMT-0600

parseDate("2018-02-08 22:30:00");
//Thu Feb 08 2018 22:30:00 GMT-0600

来源:https://stackoverflow.com/questions/48696566/getday-return-wrong-day-if-day-is-with-leading-zero

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!