Example usage for java.time LocalDate now

List of usage examples for java.time LocalDate now

Introduction

In this page you can find the example usage for java.time LocalDate now.

Prototype

public static LocalDate now() 

Source Link

Document

Obtains the current date from the system clock in the default time-zone.

Usage

From source file:Main.java

public static void main(String[] args) {
    // Create an adjuster that retruns a date after 3 months and 2 days
    TemporalAdjuster adjuster = TemporalAdjusters
            .ofDateAdjuster((LocalDate date) -> date.plusMonths(3).plusDays(2));

    LocalDate today = LocalDate.now();
    LocalDate dayAfter3Mon2Day = today.with(adjuster);
    System.out.println("Today: " + today);
    System.out.println("After 3  months  and  2  days: " + dayAfter3Mon2Day);

}

From source file:Main.java

public static void main(String[] argv) {
    LocalDate today = LocalDate.now();
    LocalDate tomorrow = today.plusDays(1);
    LocalDateTime time = LocalDateTime.now();
    LocalDateTime nextHour = time.plusHours(1);

    System.out.println("today = " + today);
    System.out.println("1) tomorrow = " + tomorrow + " \n2) tomorrow = " + today.plus(1, DAYS));
    System.out.println("local time now = " + time);
    System.out.println("1) nextHour = " + nextHour + " \n2) nextHour = " + time.plus(1, HOURS));

    LocalDate nextWeek = today.plus(1, WEEKS);
    System.out.println("Date after 1 week : " + nextWeek);

    LocalDate previousYear = today.minus(1, YEARS);
    System.out.println("Date before 1 year : " + previousYear);

    LocalDate nextYear = today.plus(1, YEARS);
    System.out.println("Date after 1 year : " + nextYear);

    LocalDate firstDayOfMonth = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
    System.out.println("firstDayOfMonth = " + firstDayOfMonth);
}

From source file:Main.java

public static void main(String[] argv) {
    List<DayOfWeek> list = new ArrayList<>();

    list = (List<DayOfWeek>) Stream.of(Month.values()).map(month -> LocalDate.now().withYear(2010).with(month)
            .with(TemporalAdjusters.lastDayOfMonth()).getDayOfWeek()).collect(Collectors.toList());

    System.out.println(list);/*www.j  a v  a 2s.  c  o m*/
}

From source file:Main.java

public static void main(String[] args) {

    LocalDate today = LocalDate.now();
    LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1);

    LocalDate nextBDay = birthday.withYear(today.getYear());

    //If your birthday has occurred this year already, add 1 to the year.
    if (nextBDay.isBefore(today) || nextBDay.isEqual(today)) {
        nextBDay = nextBDay.plusYears(1);
    }//from w w w  .  j  av  a  2 s.co  m

    Period p = Period.between(today, nextBDay);
    long p2 = ChronoUnit.DAYS.between(today, nextBDay);
    System.out.println("There are " + p.getMonths() + " months, and " + p.getDays()
            + " days until your next birthday. (" + p2 + " total)");
}

From source file:Main.java

public static void main(String[] argv) {
    System.out.println(getDSTType(LocalDate.now()));
}

From source file:Main.java

public static void main(String[] args) {
    LocalTime lt = LocalTime.of(16, 30, 5, 78899);
    format(lt, "HH:mm:ss");
    format(lt, "KK:mm:ss a");
    format(lt, "[MM-dd-yyyy][' at' HH:mm:ss]");

    ZoneId usCentral = ZoneId.of("America/Chicago");
    ZonedDateTime zdt = ZonedDateTime.of(LocalDate.now(), lt, usCentral);
    format(zdt, "MM/dd/yyyy HH:mm:ssXXX");
    format(zdt, "MM/dd/yyyy VV");
    format(zdt, "[MM-dd-yyyy][' at' HH:mm:ss]");

}

From source file:com.khartec.waltz.jobs.sample.ServerGenerator.java

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    ServerInformationDao serverDao = ctx.getBean(ServerInformationDao.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    dsl.delete(SERVER_INFORMATION).where(SERVER_INFORMATION.PROVENANCE.eq("RANDOM_GENERATOR")).execute();

    List<ServerInformation> servers = ListUtilities.newArrayList();

    IntStream/*w  w  w . j a  va2  s . c  o m*/
            .range(0,
                    10_000)
            .forEach(
                    i -> servers
                            .add(ImmutableServerInformation.builder().hostname(mkHostName(i))
                                    .environment(randomPick(SampleData.environments))
                                    .location(randomPick(SampleData.locations))
                                    .operatingSystem(randomPick(SampleData.operatingSystems))
                                    .operatingSystemVersion(randomPick(SampleData.operatingSystemVersions))
                                    .country(
                                            "UK")
                                    .assetCode(
                                            "wltz-0" + rnd.nextInt(4000))
                                    .hardwareEndOfLifeDate(rnd.nextInt(10) > 5
                                            ? Date.valueOf(
                                                    LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3)))
                                            : null)
                                    .operatingSystemEndOfLifeDate(rnd.nextInt(10) > 5
                                            ? Date.valueOf(
                                                    LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3)))
                                            : null)
                                    .virtual(rnd.nextInt(10) > 7).provenance("RANDOM_GENERATOR").build()));

    // servers.forEach(System.out::println);
    serverDao.bulkSave(servers);

}

From source file:pruebas.PruebasReserva.java

public static void main(String[] args) {
    /*Usuario user = new Usuario("email@deprueba.com");
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
    LocalDateTime horaInicio = LocalDateTime.parse("01-06-2017 08:00", formatter);
    LocalDateTime horaFin = LocalDateTime.parse("01-06-2017 22:30", formatter);
    Horario horario = new Horario(horaInicio, horaFin, 10);
            //from   w  ww.ja  va 2s.com
    GestorMesa gestor = new GestorMesa(0, "prueba1", null, null, null);
    for(int i = 0; i< 4; i++){
    gestor.addMesa(new Mesa(i,4, horario));
    }
            
            
            
    //Reservar 1 mesa comportamiento normal
    Mesa mesa = gestor.findMesa(0);
    System.out.println("El findMesa(0) da como resultado : "+ mesa.toString());
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("mesaId", "0");
    request.getSession().setAttribute("usuario", user);
            
    System.out.println(request.getSession().getAttribute("usuario"));
            
    System.out.println("Antes de reservar: " + mesa.isDisponibleNow());
    System.out.println(gestor.sentarEnMesa(request));
            
    System.out.println(mesa.isDisponibleNow());
            
    System.out.println(gestor.sentarEnMesa(request));
            
    System.out.println(gestor.levantarDeMesa(request));
    //System.out.println(gestor.sentarEnMesa(request));
            
    ZonedDateTime horaReserva = LocalDateTime.of(2017,6,1, 12,0).atZone(ZoneId.systemDefault());
    ZonedDateTime horaReserva2 = LocalDateTime.of(2017,6,1, 15,0).atZone(ZoneId.systemDefault());
    //System.out.println("Current time: " + Long.toString(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
    //System.out.println("Reservation time: " + Long.toString(horaReserva.toInstant().toEpochMilli()));
    //System.out.println("Start time: " + Long.toString(horaInicio.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
            
    request.setParameter("hora", Long.toString(horaReserva.toInstant().toEpochMilli()));
    System.out.println(gestor.reservarMesa(request));
    request.setParameter("hora", Long.toString(horaReserva2.toInstant().toEpochMilli()));
    System.out.println(gestor.reservarMesa(request));
    System.out.println(mesa.isDisponibleAt(LocalDateTime.of(2017,6,1, 15,0)));
    System.out.println(gestor.levantarDeMesa(request));
    System.out.println(mesa.isDisponibleAt(LocalDateTime.of(2017,6,1, 15,0)));
    System.out.println(gestor.reservarMesa(request));
    LocalDate hoy = LocalDate.now();
    LocalTime horaInicio = LocalTime.of(12, 30);
    LocalTime horaFin = LocalTime.of(23, 30);
    LocalDateTime defaultInicio = LocalDateTime.of(hoy, horaInicio);
    LocalDateTime defaultFin = LocalDateTime.of(hoy, horaFin);
    System.out.println("Inicio : " + defaultInicio + " y el Fin:  " + defaultFin);*/
    //Pruebas del Horario para mostrar las disponibles
    LocalDate hoy = LocalDate.now();
    LocalTime horaInicio = LocalTime.of(12, 30);
    LocalTime horaFin = LocalTime.of(23, 30);
    LocalDateTime dateTimeInicio = LocalDateTime.of(hoy, horaInicio);
    LocalDateTime dateTimeFin = LocalDateTime.of(hoy, horaFin);
    /*Horario horario = new Horario(dateTimeInicio, dateTimeFin, 10);
    System.out.println("Antes: " + horario.getHorasLibres());
            
    LocalTime horaReserva = LocalTime.of(20,0);
    LocalDateTime timeReserva = LocalDateTime.of(hoy, horaReserva);
    horario.reservarAt(timeReserva, 1);
            
    List lista = horario.getHorasLibres();
    System.out.println("Despues: " + horario.getHorasLibres());
    horario.eliminarReserva(1);
    System.out.println("Eliminada: " + horario.getHorasLibres());
    horario.reservarAt(LocalDateTime.now(), 2);
    System.out.println("Despues: " + horario.getHorasLibres());*/

}

From source file:Main.java

public static LocalDate[] nextWeekDay(LocalDate date) {

    if (date == null) {
        date = LocalDate.now();
    }//w w  w  .  j  av a  2s .c o m

    return getWeekday(date.plusWeeks(1));
}

From source file:Main.java

public static LocalDate[] previousWeekDay(LocalDate date) {
    if (date == null) {
        date = LocalDate.now();
    }/*w  w w .  ja  va 2 s  . c om*/
    return getWeekday(date.minusWeeks(1));
}