javascript - Angularjs:有没有办法从用户选择的时区创建 timeDate 对象?

标签 javascript angularjs debugging datetime timezone

Timezones

Keep in mind that Angular datetime filter uses the time zone settings of the browser. So the same application will show different time information depending on the time zone settings of the computer that the application is running on. Neither Javascript nor Angular currently supports displaying the date with a timezone specified by the developer.

<div ng-controller="MyCtrl">
<p>Using var birthday: {{birthday}}!</p>
<p>Using custom filter date: {{birthday| date}}!</p>
<p>You were born at {{birthday|date:'shortTime' }} on {{birthday|date:'mediumDate' }}!</p>
<br />Enter your birthday1:
<br />
<input ng-model="birthday" size="60" />
</div>

我的国际化应用程序需要三个单独的输入,这些输入将发送到服务器以进行进一步处理:日期、时间和时区。在我当前的 fiddle 中,用户必须在同一输入字段中键入所有三个值才能维护预期的数据绑定(bind)。一旦我尝试分离这些值,我就会松开数据绑定(bind)。这是预期的 Anguarjs 行为吗? http://jsfiddle.net/gogirl/JmYT4/ 还有更高级的: http://jsfiddle.net/gogirl/7cWbG/

有没有办法从用户选择的时区创建 timeDate 对象?由于我是 angularjs 的新手,我可能会以错误的方式处理这个问题。如果有任何现有指令可以帮助我完成一半,请告知。这里的评论http://docs.angularjs.org/api/ng.filter:date对我帮助很大,但也指出需要让开发人员变得更简单,我很乐意提供帮助。

最佳答案

使用 Date Time string format 的完整语法:

 var foo = Date.parse("1996-09-13T12:00:00.000+05:00");
 var bar = new Date(foo);
 var baz = bar.toUTCString();

引用文献

关于javascript - Angularjs:有没有办法从用户选择的时区创建 timeDate 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19091170/

相关文章:

javascript - Google 分享按钮 - 自定义 href url

javascript - 如何在按钮单击上添加类?

python - 扭曲:无用的 "AlreadyCalled"错误

javascript TypeError : Math. random 不是 chrome 上的函数

java - 如何在 netbeans 中单步执行/调试导入的 java 代码

visual-studio - Visual Studio Breakpoint,点击禁用,不删除

javascript - 通过鼠标移动绘制的矩形会在鼠标移动时不断绘制自身,同时显示之前的矩形

javascript - 用于循环异步等待的 Firebase 函数

javascript - 什么是用 .then(console.log) 调用替换 .then(data => console.log(data)) ?

javascript - Angular 排序日期排序不正确