- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在将时间从 CST 转换为本地时间,但 getTimeZone
似乎无法正常工作。
String cstTime = "2013-06-21 14:00:00";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("CST"));
Date date = null;
try {
date = simpleDateFormat.parse(cstTime);
} catch (ParseException e) {
System.out.println("Parse time error");
e.printStackTrace();
}
TimeZone destTz = TimeZone.getDefault();//here I should get EDT on my phone
simpleDateFormat.setTimeZone(destTz);
String convertedLocalTime = simpleDateFormat.format(date);
//the converted time I get is "2013-06-21 10:00:00"
//but it should be "2013-06-21 15:00:00"
它似乎使用的是 GMT 而不是 CST,下面是我在调试时得到的结果:
String abc = TimeZone.getTimeZone("CST").toString();
System.out.println("CST:"+abc);
Output:
I/System.out(19404): CST:java.util.SimpleTimeZone[id=GMT,offset=0,dstSavings=3600000,
useDaylight=false,startYear=0,startMode=0,startMonth=0,startDay=0,startDayOfWeek=0,
startTime=0,endMode=0,endMonth=0,endDay=0,endDayOfWeek=0,endTime=0]
是否使用 GMT?为什么..提前致谢!
编辑:
终于可以用了
simpleDateFormat.setTimeZone(TimeZone.getTimeZone( "GMT-5")); //GMT-5 is for CDT, I found my server is actually using CDT not CST
仍然不知道为什么使用字符串“CST”不起作用...
最佳答案
来自 getTimeZone 的 javadoc:
Returns a TimeZone corresponding to the given id, or GMT for unknown ids.
An ID can be an Olson name of the form Area/Location, such as America/Los_Angeles.
The getAvailableIDs() method returns the supported names.
尝试使用 getAvailableIDs?
关于java - TimeZone.getTimeZone ("CST") 返回 GMT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17242764/
在 /usr/share/lib/zoneinfo 下 我可以看到以下 4 种不同类型的 GMT 信息 GMT GMT+0 GMT-0 GMT0 这 4 种 GMT 区域时间之间有什么区别吗?如果是这
我有这样的输入格式,我需要将其转换为 GMT 格式: $input = array( "gmt" => "+7", "datetime" => "2017-
我尝试了以下代码,应该允许我将时间传递作为参数转换为一个多一小时 (GMT+1) 的字符串。 但我总是得到与我对象时间相同的时间 public static String getFormattedTi
为什么 GMT-0400 在 1989 年之前转变为 GMT-0500? > new Date('1989-04-02T23:01:14.52Z') Sun Apr 02 1989 19:01:14
我从服务器获取日期字符串及其 GMT+2 我认为无法转换为印度 GMT 5:30 格式 这是服务器日期字符串 2017-01-11T05:08:15.157Z 我想要印度时间格式的这个我已经尝试了下面
我每分钟运行一个任务,我想打印出当前 GMT 时间和 9PM GMT 之间的差异,我希望它一直运行,所以一旦到达 9PM GMT,它就会重置为 24 小时所以它正在寻找第二天晚上 9 点(格林威治标准
在这方面遇到了困难,尝试了所有这些不同的日期函数,但不知道如何确定地做到这一点。 最佳答案 您可以使用calendar.timegm来获取自纪元以来的秒数。时间元组是必需的参数,time.strpti
我知道有多种方法可以将日期时间转换为 Unix 时间戳。 但问题是当我们将 GMT 的日期时间值转换为 Unix 时间戳时,它会根据我本地时区的值显示时间戳的值,即 Asia/Kolkata 例如:G
当我将 user_login_date 存储到数据库中时,它是 GMT +5:30,但我的数据库设置为 GMT 0:00 用户在 12:00:00 登录但数据库将该日期存储为 07:30:00 的示例
当我使用“日期”命令时,我们的服务器提供 GMT 时间。但是我现在的时间应该是GMT+8。如何将当前时间显示为 GMT+8?提前致谢。 最佳答案 将这样的一行添加到您的 .profile 文件中,然后
我正在使用此代码获取 android 设备的 timezone TimeZone tz = TimeZone.getDefault(); String current_Time_Zone = (Tim
我也想要 GMT 字符串的时间。 但我无法得到它。 DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd/hh-mm"); dateForm
我也是 MVC3 和 C# 的新手。我将使用 C# 通过 MVC3 创建一个测试博客站点。用户可以在哪里写帖子,所以我需要存储用户帖子日期时间,并想在自己的本地时间显示每个其他用户的日期时间。对于这种
我在使用 PHP DateTime 将 GMT -8 时区 (PST) 接收的日期转换为 GMT -7 (PDT) 时区的人类可读格式时遇到困难。 这是一个例子: $tz = new DateTime
例如,我想解析下面的字符串: Tue Sep 28 18:02:24 GMT+08:00 2010 我使用 SimpleDateFormat 的模式: new SimpleDateFormat("EE
我正在尝试使用 html 输入中的信息查询数据库。日期的格式为: Date {Sun Jun 03 2012 00:00:00 GMT+0100 (GMT Daylight Time)} 在我
我有一种情况,我收到以下格式的字符串形式的日期。 “2014 年 1 月 13 日星期一 00:00:00 GMT+0000(GMT 标准时间)” 我需要在 c# 中将其转换为以下格式(日期/字符串)
我能够从完整的字符串名称“Australia/Brisbane”中获取 Java 中的时区对象 TimeZone tz = TimeZone.getTimeZone("Australia/Brisba
我能够从完整的字符串名称“Australia/Brisbane”中获取 Java 中的时区对象 TimeZone tz = TimeZone.getTimeZone("Australia/Brisba
我有这些数据可供使用: Timezone of local time as integer: 8.75 (which is UTC+8.75) 1) 2012-09-04 03:15:03 2) 20
我是一名优秀的程序员,十分优秀!