이미 언급 한 답변을 살펴 보았지만 현재 직면하고있는 문제를 해결하지 못했습니다.다른 표준 시간대의 문자열을 다른 표준 시간대의 날짜로 변환
2017-10-03T19 : 45 :
나는 같은 GMT의 String이 내가 다른 시간대로 분석 할 필요가 00.000 + 0000
. 문제는 바로 +0000
입니다. SimpleDateFormat
을 사용하여 구문 분석하려고하면 사용자의 timeZone을 사용하는 대신 서버 시간대를 고려합니다. https://www.jdoodle.com/embed/v0/java/jdk-1.8/92U
코드 :
String dateString = "2017-10-02T19:45:23.000+0000";
SimpleDateFormat parseFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+0000");
parseFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
try{
Date newDate = parseFormat.parse(dateString);
System.out.println(newDate);
parseFormat.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
String newDateString = parseFormat.format(newDate);
//Instead of +0000 it should be +05:30 but it is not so.
System.out.println(newDateString);
} catch(ParseException e){
e.printStackTrace();
}
출력 :
월 10월 2일 그리니치 표준시 19시 45분 23초 2017
2017- 여기나는 문제의 데모를 만들었습니다 10-03T01 : 15 : 23.000 + 0000
가능한 중복 (https://stackoverflow.com/questions/43518627/how-to-use-offset-time-in-java-simple-date-format) –
'+ 0000'은 UTC를 의미합니다. –
는 그리고 그것은 문제의 코드를 포함하는 것이 좋습니다, 그래서 링크를 사용할 수없는 경우, 질문은 "불완전"이되지 않습니다 https://meta.stackoverflow.com/a/339451/7605325 –