Java:如何在给定时区的月末查找时间戳

Java:如何在给定时区的月末查找时间戳,java,jodatime,Java,Jodatime,我需要在月底从给定的时间戳中找到给定时区的时间戳 以下代码返回UTC格式的月份开始时间戳 DateTime allInOneLine = new DateTime( DateTimeZone.forID( "Europe/Paris" ) ).plusMonths( 1 ).dayOfMonth().withMinimumValue().withTimeAtStartOfDay(); 返回: 2017-12-01T00:00:00.000Z 任何关于如何获取给定时区的月末时间戳的建议,下面是

我需要在月底从给定的时间戳中找到给定时区的时间戳

以下代码返回UTC格式的月份开始时间戳

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

2017-12-01T00:00:00.000Z

任何关于如何获取给定时区的月末时间戳的建议,下面是一个很好的起点。我已通过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());
    }
}

只需从下个月开始减去1ms。