Angular Material Datepicker返回确切日期的前一天 [英] Angular Material Datepicker returns one day before the exact date

查看:144
本文介绍了Angular Material Datepicker返回确切日期的前一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上使用角形材料,当我将日期发送到Web api时,它显示在所选日期的前一天。例如,如果我输入2016-01-03,则它将发送2016-01-02。我该如何解决此问题。我没有更改任何形式的代码,这些代码的格式如下:

https://material.angularjs.org/latest/demo/datepicker

解决方案

我们最近遇到了同样的问题,如
> https://github.com/angular-ui/ui-date/issues/88



工作正常。希望对某些人有所帮助。

 函数AdjustDateForTimeOffset(dateToAdjust){
var offsetMs = dateToAdjust.getTimezoneOffset()* 60000;
返回新的Date(dateToAdjust.getTime()-offsetMs);
}


Im using angular material in my web site and when I send the date to my web api, it shows on day before the selected date. For an example if I put in 2016-01-03 then it will send 2016-01-02. How can I fix this issue. I haven't change any code form the original code provided in angular material web site the link to the code is below

https://material.angularjs.org/latest/demo/datepicker

解决方案

we recently faced the same , adjusting the value before posting like said in https://github.com/angular-ui/ui-date/issues/88

works fine. Hope its helpfull for some one.

 function adjustDateForTimeOffset(dateToAdjust) {
var offsetMs = dateToAdjust.getTimezoneOffset() * 60000;
return new Date(dateToAdjust.getTime() - offsetMs);
}

这篇关于Angular Material Datepicker返回确切日期的前一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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