为什么角日期过滤器显示错误的日期? [英] Why is Angular date filter displaying wrong date?

查看:104
本文介绍了为什么角日期过滤器显示错误的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的日期输入字段,并格式化我的UI与角度选择的日期。但是格式化的日期总是比在选定的日期少1天。这是为什么,我怎么能解决这个问题?

I'm using a date input field, and formatting the selected date in my ui with Angular. But the formatted date is always 1 day less than the selected date. Why is that, and how can I fix it?

HTML

<div ng-app="miniapp">
    <div>
    <label class="control-label" for="inputStart">Start Date:</label>
        <input type="date" id="inputStart" data-ng-model="startDate" /><br />
        Selected: <span>{{ startDate }}</span><br />
        fullDate: <span>{{ startDate | date:'fullDate' }}</span><br />
        mediumDate: <span>{{ startDate | date:'mediumDate' }}</span><br />
        MMMM d yyyy<span>{{ startDate | date:'MMMM d yyyy' }}</span>
    </div>    
</div>

JS:

var app = angular.module('miniapp', []);

我有一个演示这一问题的小提琴: http://jsfiddle.net/wittersworld/uY3s9/

编辑:我更新了一个有效的解决方案小提琴: http://jsfiddle.net/ wittersworld / uY3s9 / 2 /

I updated the fiddle with a working solution: http://jsfiddle.net/wittersworld/uY3s9/2/

推荐答案

这是一个时区的问题。

如果你输入的,比方说,2013年6月8日期到您的日期选择器,那是午夜GMT。如果你住英格兰西说,在美国,它是2013年6月7日。

If you enter a date of, say, June 8, 2013 into your date picker, that's midnight GMT. If you live west of England, say, in the U.S., it's June 7, 2013.

更改行

{{ startDate | date:'fullDate' }}

{{ startDate | date:'medium' }}

看时间!

这篇关于为什么角日期过滤器显示错误的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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