私の Android アプリケーション サーバーではUTC
、次の format( yyyy-MM-dd HH:mm:ss
) 24hours で日付が返され、それらの時間をユーザーの TimeZone に変換する必要がありCST
ますIST
。
次のコードを実行しましたが、それが正しいかどうかはわかりません。正しい方法でタイムゾーンを変換するのを手伝ってください。
UTC日付をjson文字列として取得し、ユーザーのタイムゾーン形式に変換してAndroid側を表示します
private static Date utcDate;
private static DateFormat expireFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
try {
expireFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
utcDate = expireFormat.parse("2014-04-01 10:32:00");
System.out.println(TimeZone.getDefault().getID());
expireFormat.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID()));
System.out.println(expireFormat.format(utcDate));
} catch (ParseException e) {
e.printStackTrace();
}
output of the code:
Asia/Calcutta
2014-04-01 16:02:00