HTML输入类型的日期和时间,不带时区偏移 [英] HTML input type date and time without timezone offset

查看:141
本文介绍了HTML输入类型的日期和时间,不带时区偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用HTML5输入日期和输入时间进行离子显影.默认情况下,它绑定为ISO日期字符串,并更改为UTC日期时间.当用户选择日期2016-06-06时,这对我来说似乎是错误的,具体取决于时区偏移量,它可能已变为2016-06-07或2016-06-05.输入类型=时间的情况与此类似.

I am using HTML5 input date and input time for ionic development. By default, it binds as ISO Date String and change to UTC date time. It seems wrong to me as when user choose the date 2016-06-06, it may have become 2016-06-07 or 2016-06-05 depending on timezone offset. Similar situation for input type = time.

我的目的是使ISO字符串中的日期保留用户选择的日期,而不是用时区差补偿它.

What my intention is to make the Date in ISO String to remain of what user chosen instead of offset it with timezone difference.

类似于输入datetime-local之类的东西,但似乎移动设备不支持datetime-local.

Something like input datetime-local but seems that datetime-local is not supported by mobile device.

我正在找到类似输入type ="date-local"或"time-local"的东西.

I am finding something like input type="date-local" or "time-local".

推荐答案

首先,有趣的是type ="datetime"已经

First of all it is interesting that type="datetime" has been removed from the HTML5 standard and instead only "datetime-local" exists, yet it appears that not every mobile browser implements it. For type="date", it doesn't have a time component, so just use the UTC date directly. True, converting a UTC date d to local is kind of ridiculous:

  • 新日期(d.toLocaleDateString())

  • d.setMinutes(d.getMinutes()+d.getTimezoneOffset())

  • new Date(+d+d.getTimezoneOffset()*60000)

但是你能做什么?

这篇关于HTML输入类型的日期和时间,不带时区偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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