최근 프로젝트에서 시간대 문제가 발생하지 않도록 Calendar에서 LocalTime을 joda로 전환했습니다 (시간대가 필요 없음). 타임 스탬프에 LOCALDATE를 변환 한 후, 그 결과는 전날 23:00까지 다시 떨어질 내가 알아낼 수없는 이유LocalDate를 Timestamp로 변환 할 때 전날 23:00에 도착
class DateTimeUtils{
static Timestamp getDeadline(LocalDate localDate, int daysToAdd){
localDate = localDate.plusDays(daysToAdd);
System.out.println(localDate);//This prints 2017-06-02
return new Timestamp(localDate.toDateTimeAtStartOfDay().getMillis());
}
public static void main(String... args){
LocalDate localDate= new LocalDate(2017,5,31);
Timestamp timeStamp=getDeadline(localDate,2);
System.out.println(timeStamp);//This prints 2017-06-01 23:00:00.0
}
}
: 어떤 시점에서 나는 LOCALDATE에서 타임 스탬프를받을 필요가 . 왜 그런가요?
귀하의 코드는 두 가지 방법 모두에서 동일한 출력을 반환합니다 (브라질 출신) '2017-06-02'과'2017-06-02 00 : 00 : 00.0' 어쩌면 현지에서 일광 절약 back to 23:00:00 –
'localDate.toDateTimeAtStartOfDay()'는 시간대 문제를 피하지 않습니다. 그냥 기본 시간대를 사용하고 있습니다. 데이터베이스의 시간대와 JDBC 드라이버가 가정하는 시간대에 여전히 문제가 있습니다. – VGR
@ErickMaia, 내 로컬 컴퓨터에 일광 절약 시간제가 없습니다. 내 컴퓨터에서이 코드를 실행하면 0이됩니다. TimeZone timezone = TimeZone.getDefault(); System.out.println ("DayLight Saving :"+ timezone.getDSTSavings()); –