Java Code Examples for java.time.ZonedDateTime#withMinute()

The following examples show how to use java.time.ZonedDateTime#withMinute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeUtil.java    From game-server with MIT License 5 votes vote down vote up
public static long offsetCurrentTimeMillis(int offsetDays, int hour, int minute, int secord) {
    ZonedDateTime ldt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis()), ZoneId.systemDefault());
    if (offsetDays > 0) {
        ldt = ldt.plusDays(offsetDays);
    } else if (offsetDays < 0) {
        ldt = ldt.minusDays(offsetDays);
    }
    ldt = ldt.withHour(hour);
    ldt = ldt.withMinute(minute);
    ldt = ldt.withSecond(secord);
    return ldt.toEpochSecond() * 1000;
}
 
Example 2
Source File: TCKZonedDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withMinute(15), ZONE_0100));
}
 
Example 3
Source File: TCKZonedDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(30);
    assertEquals(test, base);
}
 
Example 4
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withMinute(15), ZONE_0100));
}
 
Example 5
Source File: TCKZonedDateTime.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(30);
    assertEquals(test, base);
}
 
Example 6
Source File: TCKZonedDateTime.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withMinute(15), ZONE_0100));
}
 
Example 7
Source File: TCKZonedDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withMinute(15), ZONE_0100));
}
 
Example 8
Source File: TCKZonedDateTime.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withMinute(15), ZONE_0100));
}
 
Example 9
Source File: TCKZonedDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(30);
    assertEquals(test, base);
}
 
Example 10
Source File: TCKZonedDateTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(30);
    assertEquals(test, base);
}
 
Example 11
Source File: TCKZonedDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(30);
    assertEquals(test, base);
}
 
Example 12
Source File: ZonedDateTimeAxis.java    From constellation with Apache License 2.0 4 votes vote down vote up
/**
 * Makes datetimes even, in the sense of that years always begin in January,
 * months always begin on the 1st and days always at midnight.
 *
 * @param dateTimes The list of dates.
 * @return The new list of dates.
 */
private List<ZonedDateTime> makeDateTimesEven(final List<ZonedDateTime> dateTimes) {
    // if the dates contain more dates than just the lower and upper bounds, make the dates in between even.
    if (dateTimes.size() > 2) {
        List<ZonedDateTime> evenDateTimes = new ArrayList<>();

        // for each interval, modify the date slightly by a few millis, to make sure they are different days.
        // this is because Axis stores each value and won't update the tick labels, if the value is already known.
        // this happens if you display days and then add a date many years in the future the tick label will still be displayed as day.
        for (int i = 0; i < dateTimes.size(); i++) {
            ZonedDateTime evenDateTime = dateTimes.get(i);
            switch (actualInterval.interval) {
                case YEARS:
                    // if it's not the first or last date (lower and upper bound), make the year begin with first month and let the months begin with first day.
                    if (i != 0 && i != dateTimes.size() - 1) {
                        evenDateTime = evenDateTime.withMonth(0);
                        evenDateTime = evenDateTime.withDayOfMonth(1);
                    }
                    evenDateTime = evenDateTime.withHour(0);
                    evenDateTime = evenDateTime.withMinute(0);
                    evenDateTime = evenDateTime.withSecond(0);
                    evenDateTime = evenDateTime.withNano(6 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                case MONTHS:
                    // if it's not the first or last date (lower and upper bound), make the months begin with first day.
                    if (i != 0 && i != dateTimes.size() - 1) {
                        evenDateTime = evenDateTime.withDayOfMonth(1);
                    }
                    evenDateTime = evenDateTime.withHour(0);
                    evenDateTime = evenDateTime.withMinute(0);
                    evenDateTime = evenDateTime.withSecond(0);
                    evenDateTime = evenDateTime.withNano(5 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                case WEEKS:
                    // make weeks begin with first day of week?
                    evenDateTime = evenDateTime.withHour(0);
                    evenDateTime = evenDateTime.withMinute(0);
                    evenDateTime = evenDateTime.withSecond(0);
                    evenDateTime = evenDateTime.withNano(4 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                case DAYS:
                    evenDateTime = evenDateTime.withHour(0);
                    evenDateTime = evenDateTime.withMinute(0);
                    evenDateTime = evenDateTime.withSecond(0);
                    evenDateTime = evenDateTime.withNano(3 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                case HOURS:
                    if (i != 0 && i != dateTimes.size() - 1) {
                        evenDateTime = evenDateTime.withMinute(0);
                        evenDateTime = evenDateTime.withSecond(0);
                    }
                    evenDateTime = evenDateTime.withNano(2 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                case MINUTES:
                    if (i != 0 && i != dateTimes.size() - 1) {
                        evenDateTime = evenDateTime.withSecond(0);
                    }
                    evenDateTime = evenDateTime.withNano(1 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                case SECONDS:
                    evenDateTime = evenDateTime.withNano(0 * TemporalConstants.NANOSECONDS_IN_MILLISECOND);
                    break;
                default:
                    break;
            }
            evenDateTimes.add(evenDateTime);
        }

        return evenDateTimes;
    } else {
        return dateTimes;
    }
}
 
Example 13
Source File: TCKZonedDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(30);
    assertEquals(test, base);
}
 
Example 14
Source File: TCKZonedDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withMinute(15), ZONE_0100));
}
 
Example 15
Source File: TCKZonedDateTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(30);
    assertEquals(test, base);
}
 
Example 16
Source File: TCKZonedDateTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withMinute(15), ZONE_0100));
}
 
Example 17
Source File: TCKZonedDateTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(30);
    assertEquals(test, base);
}
 
Example 18
Source File: TCKZonedDateTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withMinute(15), ZONE_0100));
}
 
Example 19
Source File: TCKZonedDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(30);
    assertEquals(test, base);
}
 
Example 20
Source File: TCKZonedDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_withMinute_normal() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withMinute(15);
    assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withMinute(15), ZONE_0100));
}