當前位置: 首頁>>代碼示例>>Java>>正文


Java TemporalAdjusters類代碼示例

本文整理匯總了Java中java.time.temporal.TemporalAdjusters的典型用法代碼示例。如果您正苦於以下問題:Java TemporalAdjusters類的具體用法?Java TemporalAdjusters怎麽用?Java TemporalAdjusters使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TemporalAdjusters類屬於java.time.temporal包,在下文中一共展示了TemporalAdjusters類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createFutureEvent

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
/**
 * Set up an event to hang the bets off  
 */
public default void createFutureEvent() {
    // Grab some horses to use as runners in races
    final IMap<Horse, Object> fromHC = getClient().getMap("winners");
    final Set<Horse> horses = fromHC.keySet();

    // Now set up some future-dated events for next Sat
    final LocalDate nextSat = LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.SATURDAY));
    LocalTime raceTime = LocalTime.of(11, 0); // 1100 start
    final Event e = CentralFactory.eventOf("Racing from Epsom", nextSat);
    final Set<Horse> runners = makeRunners(horses, 10);
    for (int i = 0; i < 18; i++) {
        final Map<Horse, Double> runnersWithOdds = makeSimulatedOdds(runners);
        final Race r = CentralFactory.raceOf(LocalDateTime.of(nextSat, raceTime), runnersWithOdds);
        e.addRace(r);

        raceTime = raceTime.plusMinutes(10);
    }
    final IMap<Long, Event> events = getClient().getMap("events");
    events.put(e.getID(), e);
}
 
開發者ID:hazelcast,項目名稱:betleopard,代碼行數:24,代碼來源:RandomSimulationUtils.java

示例2: toIntervalStart

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
public ZonedDateTime toIntervalStart(ZonedDateTime time) {
    ZonedDateTime start;
    switch (ChronoUnit.valueOf(unit.toString().toUpperCase())) {
        case SECONDS:
            start = time.truncatedTo(ChronoUnit.MINUTES);
            break;
        case MINUTES:
            start = time.truncatedTo(ChronoUnit.HOURS);
            break;
        case HOURS:
            start = time.truncatedTo(ChronoUnit.DAYS);
            break;
        case DAYS:
            start = time.with(TemporalAdjusters.firstDayOfYear()).truncatedTo(ChronoUnit.DAYS);
            break;
        default:
            start = time.with(TemporalAdjusters.firstDayOfYear()).truncatedTo(ChronoUnit.DAYS);
    }
    long haveMillis = Duration.between(start, time).toMillis();
    long maxMillis = duration.toMillis();
    long periods = haveMillis / maxMillis;
    start = start.plus(duration.multipliedBy(periods));
    return start;
}
 
開發者ID:hylkevds,項目名稱:SensorThingsProcessor,代碼行數:25,代碼來源:ProcessorBatchAggregate.java

示例3: PrintfMouth

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
public static void PrintfMouth(LocalDate ldb){
    LocalDate lde = ldb.with(TemporalAdjusters.lastDayOfMonth());
    
    String mouth = ldb.getMonth().toString();
    System.out.println(mouth.substring(0, 1) + mouth.substring(1).toLowerCase() + " " + Integer.toString(ldb.getYear()));
    System.out.println("Su Mo Tu We Th Fr Sa");

    for(int i = 1; i<=lde.getDayOfMonth() + ldb.getDayOfWeek().getValue(); i++){
        if(i<=ldb.getDayOfWeek().getValue()){
            System.out.print("   ");
        }
        else{
            System.out.print(String.format("%02d ", i - ldb.getDayOfWeek().getValue()));
        }
        if(i%7==0){
            System.out.println();
        }
    }
}
 
開發者ID:starsriver,項目名稱:JavaHomework,代碼行數:20,代碼來源:cal.java

示例4: getCurrentTimesheetWeekEndDate

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
/**
 * Returns java.util weekend date (Sunday) based on the current local date.
 *
 * @return
 */
public static Date getCurrentTimesheetWeekEndDate() {
    LocalDate lastSunday = LocalDate.now()
            .with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
    log.info("lastSunday: " + lastSunday);
    return Date.from(lastSunday.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
 
開發者ID:Mahidharmullapudi,項目名稱:timesheet-upload,代碼行數:12,代碼來源:DateUtils.java

示例5: test_next

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
@Test
public void test_next() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);

            for (DayOfWeek dow : DayOfWeek.values()) {
                LocalDate test = (LocalDate) TemporalAdjusters.next(dow).adjustInto(date);

                assertSame(test.getDayOfWeek(), dow, date + " " + test);

                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff > 0 && dayDiff < 8);
                } else {
                    assertSame(month, Month.DECEMBER);
                    assertTrue(date.getDayOfMonth() > 24);
                    assertEquals(test.getYear(), 2008);
                    assertSame(test.getMonth(), Month.JANUARY);
                    assertTrue(test.getDayOfMonth() < 8);
                }
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:TCKTemporalAdjusters.java

示例6: resolveYMD

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
ChronoLocalDate resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
    if (resolverStyle == ResolverStyle.LENIENT) {
        long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
        long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
        return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
    }
    int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
    ValueRange domRange = range(DAY_OF_MONTH);
    int dom = domRange.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
    if (resolverStyle == ResolverStyle.SMART) {  // previous valid
        try {
            return date(y, moy, dom);
        } catch (DateTimeException ex) {
            return date(y, moy, 1).with(TemporalAdjusters.lastDayOfMonth());
        }
    }
    return date(y, moy, dom);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:20,代碼來源:AbstractChronology.java

示例7: instantOfNextFrame

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
@Override
public Instant instantOfNextFrame(final Instant instant) {
    final ZonedDateTime britishTime = instant.atZone(BRITISH_TIME_ZONE);
    final DayOfWeek britishDay = britishTime.getDayOfWeek();
    if (britishDay != SUNDAY) {
        return removeMinutesAndLess(britishTime).withHour(0).plus(1, DAYS).toInstant();
    }

    final ZonedDateTime britishTimeCorrectTimeValues = removeMinutesAndLess(britishTime).withHour(22);
    if (britishTime.getDayOfWeek() == SUNDAY) {
        if (britishTime.isBefore(britishTimeCorrectTimeValues)) {
            return britishTimeCorrectTimeValues.toInstant();
        }
        return removeMinutesAndLess(britishTime).withHour(0).plus(2, DAYS).toInstant();
    }
    return britishTimeCorrectTimeValues.with(TemporalAdjusters.next(SUNDAY)).toInstant();
}
 
開發者ID:rbi,項目名稱:trading4j,代碼行數:18,代碼來源:D1.java

示例8: test_previous

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
@Test
public void test_previous() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);

            for (DayOfWeek dow : DayOfWeek.values()) {
                LocalDate test = (LocalDate) TemporalAdjusters.previous(dow).adjustInto(date);

                assertSame(test.getDayOfWeek(), dow, date + " " + test);

                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff < 0 && dayDiff > -8, dayDiff + " " + test);
                } else {
                    assertSame(month, Month.JANUARY);
                    assertTrue(date.getDayOfMonth() < 8);
                    assertEquals(test.getYear(), 2006);
                    assertSame(test.getMonth(), Month.DECEMBER);
                    assertTrue(test.getDayOfMonth() > 24);
                }
            }
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:TCKTemporalAdjusters.java

示例9: test_lastInMonth

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
@Test(dataProvider = "dayOfWeekInMonth_negative")
public void test_lastInMonth(int year, int month, DayOfWeek dow, LocalDate expected) {
    for (int day = 1; day <= Month.of(month).length(false); day++) {
        LocalDate date = date(year, month, day);
        LocalDate test = (LocalDate) TemporalAdjusters.lastInMonth(dow).adjustInto(date);
        assertEquals(test, expected, "day-of-month=" + day);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:TCKTemporalAdjusters.java

示例10: test_lastDayOfYear_nonLeap

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
@Test
public void test_lastDayOfYear_nonLeap() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);
            LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfYear().adjustInto(date);
            assertEquals(test.getYear(), 2007);
            assertEquals(test.getMonth(), Month.DECEMBER);
            assertEquals(test.getDayOfMonth(), 31);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:TCKTemporalAdjusters.java

示例11: main

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
public static void main(String[] args) {
    LocalDate ldb = null;
    try{
        if(args[0].length() == 1){
            args[0] = "0" + args[0];
        }
        ldb = LocalDate.parse(args[0] + args[1] + "01",DateTimeFormatter.ofPattern("MMyyyydd"));
    }
    catch(Exception e){
        ldb = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
    }
    PrintfMouth(ldb);
}
 
開發者ID:starsriver,項目名稱:JavaHomework,代碼行數:14,代碼來源:cal.java

示例12: formattedPlannedDay

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
private String formattedPlannedDay(DayOfWeek dayOfDeparture) {
    LocalDateTime today = LocalDateTime.now(IN_SYDNEY).withHour(0).withMinute(0).withSecond(0).withNano(0);
    LocalDateTime plannedDay = today.with(TemporalAdjusters.nextOrSame(dayOfDeparture));

    if (DAYS.between(today, plannedDay) == 0) {
        return "Today (" + plannedDay.format(DateTimeFormatter.ofPattern("EEE")) + ")";
    } else if (DAYS.between(today, plannedDay) == 1) {
        return "Tomorrow (" + plannedDay.format(DateTimeFormatter.ofPattern("EEE")) + ")";
    } else {
        return plannedDay.format(DateTimeFormatter.ofPattern("dd MMM (EEE)"));
    }
}
 
開發者ID:serenity-bdd,項目名稱:journey-planner,代碼行數:13,代碼來源:SelectDepartureDate.java

示例13: getLocalTimesheetWeekEndDate

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
/**
 * Returns java.time LocalDate weekend date (Sunday) based on the current local date.
 *
 * @return
 */
public static LocalDate getLocalTimesheetWeekEndDate() {
    log.info("Inside getLocalTimesheetWeekEndDate");
    LocalDate lastSunday = LocalDate.now()
            .with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
    log.info("lastSunday: " + lastSunday);
    return lastSunday;
}
 
開發者ID:Mahidharmullapudi,項目名稱:timesheet-upload,代碼行數:13,代碼來源:DateUtils.java

示例14: getLocalTimesheetWeekStartDate

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
/**
 * Returns java.time LocalDate weekend date (Sunday) for a given date.
 *
 * @return
 */
public static LocalDate getLocalTimesheetWeekStartDate(Date inputDate) {
    log.info("Inside getLocalTimesheetWeekStartDate :: inputDate: " + inputDate);
    if (inputDate != null) {
        LocalDate localDate = inputDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        LocalDate firstMonday = localDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
        log.info("Inside inputDate not null loop, firstMonday: " + firstMonday);
        return firstMonday;
    } else {
        log.error("Input date not found. So returning null.");
        return null;
    }
}
 
開發者ID:Mahidharmullapudi,項目名稱:timesheet-upload,代碼行數:18,代碼來源:DateUtils.java

示例15: getTimesheetWeekEndDate

import java.time.temporal.TemporalAdjusters; //導入依賴的package包/類
/**
 * Returns java.util weekend date (Sunday) for a given date.
 *
 * @return
 */
public static Date getTimesheetWeekEndDate(Date inputDate) {
    log.info("Inside getTimesheetWeekEndDate :: inputDate: " + inputDate);
    if (inputDate != null) {
        LocalDate localDate = inputDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        LocalDate lastSunday = localDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
        log.info("Inside input date not null loop, lastSunday: " + lastSunday);
        return Date.from(lastSunday.atStartOfDay(ZoneId.systemDefault()).toInstant());
    } else {
        log.error("Input date not found. So returning null.");
        return null;
    }
}
 
開發者ID:Mahidharmullapudi,項目名稱:timesheet-upload,代碼行數:18,代碼來源:DateUtils.java


注:本文中的java.time.temporal.TemporalAdjusters類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。