내 Android 애플리케이션 서버에서 다음과 같은 형식 (yyyy-MM-dd HH:mm:ss
)의 날짜를 UTC
(으)로 반환하고 해당 시간을 사용자의 TimeZone으로 변환해야합니다. 예 : CST
, IST
. UTC 시간을 다른 표준 시간대 ("CST", "IST")로 변환하는 방법
내가 JSON 문자열로 UTC 날짜를 얻고 재 포맷 문자열은 정말 당신이 무슨 말을 하려는지 경우
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
에는 TimeZone.getDefault(). getOffset (now.getTime()), 현재 사용자의 현재 시간이 긴 경우, GMT 오프셋 장치의 시간대를 제공한다. – mraviator