AngularUI DatePicker - JavaScript - 获取 SQL 日期格式时的日期休息一天 [英] AngularUI DatePicker - JavaScript - Date one day off when getting SQL Date format

查看:28
本文介绍了AngularUI DatePicker - JavaScript - 获取 SQL 日期格式时的日期休息一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 SQL 格式的日期加载到变量 "2014-02-28" 中,但是当我创建一个

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

在 AngularUI 日期选择器中,即使模型中的值是正确的,日期也始终是一天.有什么办法可以解决这个问题吗?

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?

这是一个演示问题的 Plunkr 链接:http://plnkr.co/edit/evBwPW0KO7cEWGp6vqtk?p=预览

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

我希望模型只是 yyyy-MM-dd 格式的日期,并且日期是正确的.

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

推荐答案

将日期格式更改为

yyyy/MM/dd 

解决了问题

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

这篇关于AngularUI DatePicker - JavaScript - 获取 SQL 日期格式时的日期休息一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆