当前位置: 首页>>代码示例>>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;未经允许,请勿转载。