마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

gmt 시간을 utc 시간으로 변환

0 추천
gmt + 9 시간을 UTC 시간으로 변환이 가능한가요?

String strGmt = "2018-01-02 09:00"

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm", java.util.Locale.getDefault());
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

String strUtc = dateFormat.format(strGmt);

Date utcDate = dateFormat.parse(strUtc);

변환이 안되고 있는데 무얼 잘못 생각하고 있는지 모르겠습니다...;
익명사용자 님이 2018년 1월 2일 질문

1개의 답변

0 추천
 
채택된 답변
String strGmt = "2018-01-02 09:00";

SimpleDateFormat localDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");

SimpleDateFormat utcDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
utcDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

Date localDate = localDateFormat.parse(strGmt);
Date utcDate  = localDateFormat.parse(utcDateFormat.format(localDate));

 

디자이너정 (42,810 포인트) 님이 2018년 1월 2일 답변
...