- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试使用时区和区域设置转换日期和时间,但是它在 IE11 中不起作用。它适用于 chrome、firefox 和 edge。
最小完整的可验证示例:
function getLocalTime(date){
var timeZone = "Asia/Kolkata";
var utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()));
var dateAndTime = utcDate.toLocaleDateString("en",{timeZone:timeZone})+" "+ utcDate.toLocaleTimeString("en",{timeZone:timeZone}).replace(/:\d+ /, ' ');;
return dateAndTime;
}
console.log(getLocalTime(Date());
IE11 错误:
SCRIPT5118:“timeZone”的选项值“ASIA/KOLKATA”超出有效范围。预期:['UTC']
注意:我不想使用任何第三方js。
最佳答案
timeZone documentation on MDN说对时区字符串的支持是可选的,除了“UTC”:
The only value implementations must recognize is "UTC"; the default is the runtime's default time zone. Implementations may also recognize the time zone names of the IANA time zone database, such as "Asia/Shanghai", "Asia/Kolkata", "America/New_York".
ECMAScript spec 的相关部分确认这一点(向@mkaatman 致敬):
[[timeZone]] is either the String value "UTC" or undefined.
A conforming implementation is permitted to accept additional values, and then have implementation-defined behaviour instead of throwing a RangeError, for [...t]he options property timeZone in the DateTimeFormat constructor, provided that the additional acceptable input values are case-insensitive matches of Zone or Link identifiers in the IANA time zone database and are canonicalized to Zone identifiers in the casing used in the database for the timeZone property of the object returned by DateTimeFormat.resolvedOptions, except that "Etc/GMT" shall be canonicalized to "UTC".
Microsoft's documentation表示他们开始在 IE11 中支持 localeDateString:
Starting in Internet Explorer 11, toLocaleDateString uses Intl.DateTimeFormat internally to format the date, which adds support for the locales and options parameters.
...但是根据您的错误消息,他们支持最小的“'UTC' 或未定义”版本。时区数据库是here对于它的值(value),但看起来您需要找到一种不同的方法来处理这个问题(可能涉及 getTimezoneOffset()
而不是命名时区。)
关于javascript - date.toLocaleDateString(locale,{timeZone :'Asia/Kolkata' }) 在 ie 11 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44402560/
我需要以 [+/-]hh:mm 格式保存手机的时区 我正在使用 TimeZone 类来处理这个问题,但我能得到的唯一格式如下: PST -05:00 GMT +02:00 我宁愿不对结果进行子串化,是
我正在尝试在 Node js 中使用 moment-timezone 来获取所有可用时区的列表,如下所示 - var moment = require('moment-timezone'); var
我正在使用以下代码将时区 (GMT-3) 转换为设备本地时区。 int hour=17,minute=0,day=12,month=6,year=2014; Calendar cal = new Gr
System.setProperty("user.timezone", "America/Chicago"); TimeZone.setDefault(TimeZone.getTimeZone("美国
我想从字符串初始化DateFormatter().timeZone,但是当我做类似的事情时 let dateFormatter = DateFormatter() dateFormatter.time
我通过存储日期组件字典在我的后端存储用户出生日期。它看起来像这样: { "day": 1, "month": 1, "year": 1970, "timeZone":
我一直在开发一个应用程序,它以下面给出的特定格式从服务器获取日期。 "2015-02-03 00:00:00" 我想使用 NSDateFormatter 以不同的 UI 格式显示它们但是当我更改时区时
我有什么 我有一个来自服务器的日期字符串,它的格式是 w3c 日期格式 2016-02-13T09:53:49.871Z 我的问题 当我将消息发布到服务器时,它显示的是 5 小时前而不是现在 我想要什
我正在将我的项目从 Django 1.8.2 升级到 1.9.7,我收到了这个警告: WARNINGS: my_app.my_model.date_available: (fields.W161) F
在下面的代码中: from datetime import datetime import pytz EDT = pytz.timezone('US/Eastern') d1 = datetime.n
我通过以下方式将服务器(Ubuntu 12.04)的时区更改为UTC: echo 'UTC' > /etc/timezone dpkg-reconfigure --frontend nonintera
我想获取洛杉矶的时区信息,现在10/10/2017是夏令时,但是我通过两种方式获取洛杉矶的时区得到了不同的结果。 public class TimeZoneDemo2 { public stati
我把它放在应用程序 Controller 中: before_filter :set_timezone def set_timezone Time.zone = current_user.time_
是否可以转换java.util.TimeZone字符串 sun.util.calendar.ZoneInfo[id=\"America/Los_Angeles\",offset=-28800000,d
当我写这段代码时: Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("EST"));
我正在使用 Java 8, 在我们的代码的前面,我们使用 sdf.setTimeZone(TimeZone.getTimeZone("PDT")); 转换为失败的美国太平洋地区(没有抛出任何错误,但转
我不断收到此警告:timezone of object (UTC) is different than current timezone ().我当前的时区是“EET”,如 Sys.timezone(
我正在我的网站上使用时刻时区转换器进行时区日期转换。默认情况下,我在 IST 中显示日期和时间。我有一个按钮可以转换用户时区中的给定时间。此按钮操作调用 moment js 并进行转换。到这里我没有问
我从服务响应中获得时区偏移量为“-5.00”,我需要在 UI 中将其格式化为 CST。我如何在 JavaScript 中转换它?我搜索了一下,不确定JavaScript中有没有直接的方法。 最佳答案
这个问题在这里已经有了答案: Converting string to datetime object (2 个答案) 关闭 6 年前。 我的主机有 UTC 时区,我正在尝试将 PDT 时间字符串转
我是一名优秀的程序员,十分优秀!