AngularUI DatePicker - JavaScript - Date one day off when getting SQL Date format

谁说我不能喝 提交于 2019-12-13 18:37:09

问题


I load in a SQL format date into a variable "2014-02-28" , but when I create a

new Date("2014-02-28");

the Date displayed in the input box is:

2014-02-27

In the AngularUI datepicker, the date is always one day off even if the value is correct in the model. Is there some way to remedy this?

Here is a Plunkr link which demonstrates the problem: http://plnkr.co/edit/evBwPW0KO7cEWGp6vqtk?p=preview

I would like the model to be just the date in yyyy-MM-dd format, and for the date to be correct.


回答1:


Changing the Date format to

yyyy/MM/dd 

fixed the problem

var date = new Date("2014-02-28"); // date loaded in SQL format
date.replace(new RegExp("-", 'g'),"/"); // now datepicker will show correct date


来源:https://stackoverflow.com/questions/22105909/angularui-datepicker-javascript-date-one-day-off-when-getting-sql-date-forma

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