에 기본적으로하지 않습니다 나는 다음과 같은 코드를 가지고있다. 자바 날짜 시간의 문자열 형식은 gmt + 0입니다. 따라서 나중에 다른 지역의 시간대에 따라 변환해야하지만 기본 시간대를 설정하려고하면 그것은 나에게 2017년 12월 9일 09:00 보여주는 내 컴퓨터가 그리니치 표준시 + 8. 출력에 원인이 다시 또 다른 8 시간 계속 : 00하지만 GMT + 0이기 때문에 2017-12-09 17:00:00으로 유지하고 싶습니다.자바 세트 시간대는 GMT + 0
String existingTime = "2017-12-09 17:00:00";
String newTime = "2017-12-09 14:00:00";
Date existingDateTime = null;
Date newDateTime = null;
Date localexistingDateTime = null;
Date localnewDateTime = null;
DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
TimeZone tz = TimeZone.getDefault();
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
// sdf.setTimeZone(TimeZone.getTimeZone("GMT+8:30"));
try {
existingDateTime = dateTimeFormat.parse(existingTime);
newDateTime = dateTimeFormat.parse(newTime);
System.out.println("GMT existingDateTime" + sdf.format(existingDateTime));
System.out.println("GMT newDateTime" + sdf.format(newDateTime));
} catch (ParseException ex) {
System.out.println("MyError:Parse Error has been caught for date parse close");
ex.printStackTrace(System.out);
}
. 대신에 유즈 케이스에 적합한 적절한 클래스를'java.time' 패키지에서 찾아야한다. –
@ JoeC 그래서이 문제를 극복하기위한 당신의 제안은 무엇입니까? – user8012596
나의 제안은'java.util.Date' 사용을 중지하고 대신'java.time' 패키지의 클래스를 사용하는 것입니다. –