如何解析日期从GMT时区为IST的时区和反之亦然机器人 [英] How to Parse Date from GMT TimeZone to IST TimeZone and Vice Versa in android
问题描述
我的工作是获取日期/时间从后端的北京时间
如图一期工程(印度标准时间)2013-01-09T19 :32:49.103 + 05:30
。然而,当我使用下面的日期格式解析
日期格式自卫队=新的SimpleDateFormat(YYYY-MM-dd'T'HH:MM:ss.SSSZ);
接着解析。
日期日期= sdf.parse(2013-01-09T19:32:49.103 + 05:30);
的System.out.println(XYZ ==============>+日期);
其显示在格林尼治标准时间的格式输出,例如日期
周三09年1月14时02分49秒GMT + 00:00 2013。
我已经尝试过使用TimeZone类的..
时区的timeZone = TimeZone.getTimeZone(IST);
sdf.setTimeZone(的timeZone);
但没有效果。
我怎么能获得日期
类对象有日期的北京时间
格式而不是GMT ...
请提供一个合适的解决方案。
编辑:
这是如何code是这样的:
的SimpleDateFormat自卫队=新的SimpleDateFormat(YYYY-MM-dd'T'HH:MM:ss.SSSZ);
时区的timeZone = TimeZone.getTimeZone(IST);
sdf.setTimeZone(的timeZone);
日期日期= sdf.parse(2013-01-09T19:32:49.103 + 05:30);
字符串formattedDate = sdf.format(日期);
的System.out.println(XYZ ==============>中+ formattedDate);
日期没有任何时区。这是毫秒数仅自1970年1月1日00:00:00 GMT的持有者。就拿您用来解析相同的日期格式,设置IST时区和格式化你的日期在下面的例子中
日期格式自卫队=新的SimpleDateFormat(YYYY-MM-dd'T'HH:MM:ss.SSSXXX);
日期日期= sdf.parse(2013-01-09T19:32:49.103 + 05:30);
sdf.setTimeZone(TimeZone.getTimeZone(IST));
的System.out.println(sdf.format(日期));
输出
2013-01-09T19:32:49.103 + 05:30
注意 XX
X图形用于ISO 8601时区(-08:00),因为1.7。如果你在1.6试试以Z
。参见SimpleDateFormat的API为格式模式的细节
I am working on a project that fetches Date/Time from backend in IST
(Indian standard Time) as shown "2013-01-09T19:32:49.103+05:30"
. However when i parse it using following DateFormat
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
followed by parsing..
Date date = sdf.parse("2013-01-09T19:32:49.103+05:30");
System.out.println("XYZ ==============>"+date);
its Displaying date in GMT format as output i.e
Wed Jan 09 14:02:49 GMT+00:00 2013.
I have tried it using TimeZone class as..
TimeZone timeZone=TimeZone.getTimeZone("IST");
sdf.setTimeZone(timeZone);
but no effect..
How could i get a Date
class Object having Date in IST
format instead of GMT...
Please provide an appropriate solution..
EDIT:
This is how Code Looks Like:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
TimeZone timeZone=TimeZone.getTimeZone("IST");
sdf.setTimeZone(timeZone);
Date date = sdf.parse("2013-01-09T19:32:49.103+05:30");
String formattedDate=sdf.format(date);
System.out.println("XYZ ==============>"+formattedDate);
Date does not have any time zone. It is just a holder of the number of milliseconds since January 1, 1970, 00:00:00 GMT. Take the same DateFormat that you used for parsing, set IST timezone and format your date as in the following example
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
Date date = sdf.parse("2013-01-09T19:32:49.103+05:30");
sdf.setTimeZone(TimeZone.getTimeZone("IST"));
System.out.println(sdf.format(date));
output
2013-01-09T19:32:49.103+05:30
Note that XX
X pattern is used for ISO 8601 time zone (-08:00) since 1.7. If you are in 1.6 try Z
. See SimpleDateFormat API for details of format patterns
这篇关于如何解析日期从GMT时区为IST的时区和反之亦然机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!