这是我将ISO转换为IST和ISO转换为GMT的代码。
Log.e("ISO TIME",""+time);//The time which i got from JSON file.
//IST TIME ZONE
Date date=new Date();
DateFormat format=DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL);
SimpleDateFormat simpleDateFormat=new SimpleDateFormat();
simpleDateFormat.applyPattern("yyyy-MM-dd'T'HH:mm'+00':ss");
date = simpleDateFormat.parse(time.toString());
format.setTimeZone(simpleDateFormat.getTimeZone());
Log.e("IST TIME", "" + format.format(date));
//GMT TIME ZONE
Date date1=new Date();
SimpleDateFormat sdf=(SimpleDateFormat)DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL);
sdf.applyPattern("yyyy-MM-dd'T'HH:mm'+00':ss");
date1=sdf.parse(time);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
Log.e("GMT TIME", "" + sdf.format(date1));
在这里,是我的输出
E/ISO TIME: 2016-01-18T08:40+00:00
E/GMT TIME: 2016-01-18T03:10+00:00
E/IST TIME: Jan 18, 2016 8:40:00 AM India Standard Time
问题是IST和GMT之间的实际差异是5:30但是在我的输出中,我得到了正好 5:30 的差异
请帮我解决这个问题。
@Logic绝对是对的。但我有一些建议给你。
您需要在格林威治标准时间中添加 5:30 小时,然后您将获得 IST。切勿将您添加到 IST 时间的 5:30 小时。
看看这个例子您的 IST 时间是 8:40,格林威治标准时间是 3:10
每个操作增加 1 小时
在圆括号中,每次迭代添加一小时:
3:10->4:10(1)->5:10(2)->6:10(3)->7:10(4)->8:10(5)
完成一小时的剩余 IST 时间分钟数为 00:20
将 00:20 添加到 8:10 它将变为 8:30。
花费格林尼治标准时间进行添加3:20
你的代码是绝对正确的