2017-11-04 1 views
0

주어진 시간 소인에서 주어진 시간대에 대해 월말에 시간 소인을 찾는 요구 사항이 있습니다.Java : 지정된 시간대에 대해 월말에 시간 소인을 찾는 방법

다음 코드는 UTC에

DateTime allInOneLine = new DateTime(DateTimeZone.forID("Europe/Paris")).plusMonths(1).dayOfMonth().withMinimumValue().withTimeAtStartOfDay(); 

수익을 달 타임 스탬프의 시작을 반환 : 나는 주어진 시간대에 대한 최종 개월 타임 스탬프를 얻을 수있는 방법

2017-12-01T00:00:00.000Z 

어떤 제안

+0

https://docs.oracle.com/javase/8/docs/api/java/time/temporal/TemporalAdjusters.html#lastDayOfMonth-에 대한 일반적인 만들 수 있습니다 - – IEE1394

+0

그냥 다음 달에 시작해서 1ms를 뺍니다. – dpr

답변

1

다음은 좋은 출발점입니다. 내가 UTC에 통과 한이 어떤 시간대

import java.time.LocalTime; 
import java.time.ZonedDateTime; 
import java.time.temporal.TemporalAdjusters; 
import static java.time.ZoneOffset.UTC; 

public class TruncateToMonth { 
    public static void main(String[] args) { 
     ZonedDateTime now = ZonedDateTime.now(UTC); 
     ZonedDateTime truncatedToMonth = now.with(TemporalAdjusters.lastDayOfMonth()).with(LocalTime.MAX); 
     System.out.println(truncatedToMonth); 
     System.out.println(truncatedToMonth.toInstant().getEpochSecond()); 
    } 
} 
관련 문제