Example usage for java.time LocalDateTime of

List of usage examples for java.time LocalDateTime of

Introduction

In this page you can find the example usage for java.time LocalDateTime of.

Prototype

public static LocalDateTime of(LocalDate date, LocalTime time) 

Source Link

Document

Obtains an instance of LocalDateTime from a date and time.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(LocalDate.now(), LocalTime.NOON);

    System.out.println(a);
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.now();
    LocalTime time = LocalTime.now();
    LocalDateTime dateTimeFromDateAndTime = LocalDateTime.of(date, time);

    System.out.println(dateTimeFromDateAndTime);

    LocalDate dateFromDateTime = LocalDateTime.now().toLocalDate();
    LocalTime timeFromDateTime = LocalDateTime.now().toLocalTime();

    System.out.println(dateFromDateTime);

    System.out.println(timeFromDateTime);
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate ld = LocalDate.of(2014, Month.JUNE, 21);
    LocalTime lt = LocalTime.of(17, 30, 20);
    LocalDateTime ldt = LocalDateTime.of(ld, lt);

    DateTimeFormatter fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
    System.out.println("Formatter  Default Locale: " + fmt.getLocale());
    System.out.println("Short  Date: " + fmt.format(ld));

    fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);
    System.out.println("Medium Date: " + fmt.format(ld));

    fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
    System.out.println("Long  Date: " + fmt.format(ld));

    fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL);
    System.out.println("Full  Date: " + fmt.format(ld));

    fmt = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
    System.out.println("Short Time:  " + fmt.format(lt));

    fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);
    System.out.println("Short  Datetime: " + fmt.format(ldt));

    fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM);
    System.out.println("Medium Datetime: " + fmt.format(ldt));

    // Use German locale to format the datetime in medius style
    fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(Locale.GERMAN);
    System.out.println(fmt.format(ldt));

    // Use Indian(English) locale to format datetime in short style
    fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(new Locale("en", "IN"));
    System.out.println(fmt.format(ldt));

    // Use Indian(English) locale to format datetime in medium style
    fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(new Locale("en", "IN"));
    System.out.println(fmt.format(ldt));

}

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);
            /*ww  w.  j  a v  a2s. c  o  m*/
    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:mServer.tool.MserverDatumZeit.java

public static long getSecondsUntilNextDay() {
    // now//ww  w  . j av  a 2s  .co m
    LocalDateTime now = LocalDateTime.now();
    // tomorrow 0:00
    LocalDateTime future = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).plusDays(1L);
    Duration duration = Duration.between(now, future);
    return duration.getSeconds();
}

From source file:defaultmethods.SimpleTimeClient.java

public void setTime(int hour, int minute, int second) {
    LocalDate currentDate = LocalDate.from(dateAndTime);
    LocalTime timeToSet = LocalTime.of(hour, minute, second);
    dateAndTime = LocalDateTime.of(currentDate, timeToSet);
}

From source file:defaultmethods.SimpleTimeClient.java

public void setDate(int day, int month, int year) {
    LocalDate dateToSet = LocalDate.of(day, month, year);
    LocalTime currentTime = LocalTime.from(dateAndTime);
    dateAndTime = LocalDateTime.of(dateToSet, currentTime);
}

From source file:defaultmethods.SimpleTimeClient.java

public void setDateAndTime(int day, int month, int year, int hour, int minute, int second) {
    LocalDate dateToSet = LocalDate.of(day, month, year);
    LocalTime timeToSet = LocalTime.of(hour, minute, second);
    dateAndTime = LocalDateTime.of(dateToSet, timeToSet);
}

From source file:net.bis5.slack.command.gcal.SlashCommandApi.java

@RequestMapping(path = "/execute", method = RequestMethod.POST)
public ResponseEntity<String> execute(@ModelAttribute RequestPayload payload) {
    log.info("Request: " + payload.toString());

    EventRequest event = payload.createEvent();
    log.info("Parsed Request: " + event.toString());

    try {/*from w  ww  . j a  v  a 2 s.  co  m*/
        Event result = client.events().insert(config.getTargetCalendarId(), createEvent(event)).execute();
        log.info("Event Create Result: " + result.toString());

        ResponsePayload response = new ResponsePayload();
        Date date = toDate(event.getDate().atStartOfDay());
        Date start = toDate(LocalDateTime.of(event.getDate(), event.getFrom()));
        Date end = toDate(LocalDateTime.of(event.getDate(), event.getTo()));
        String user = payload.getUser_name();
        String title = event.getTitle();
        response.setText(String.format(
                "%s?????\n: %tY/%tm/%td\n: %tH:%tM\n: %tH:%tM\n??: %s", //
                user, date, date, date, start, start, end, end, title));

        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            ObjectMapper mapper = new ObjectMapper();
            String responseBody = mapper.writeValueAsString(response);
            log.info("Response Payload: " + responseBody);
            Request.Post(payload.getResponse_url()).bodyString(responseBody, ContentType.APPLICATION_JSON)
                    .execute();
        }

        return ResponseEntity.ok(null);
    } catch (IOException ex) {
        log.error(ex.toString());
        return ResponseEntity.ok(ex.getMessage()); // OK??????????
    }
}

From source file:com.epam.ta.reportportal.database.search.FilterRules.java

public static Predicate<String> timeStamp() {
    return value -> {
        if (value == null) {
            return false;
        }//from w ww .  ja  v  a2  s.c  o  m
        try {
            long offset = Long.parseLong(value);
            LocalDateTime.of(LocalDate.now(), LocalTime.of(0, 0)).plusMinutes(offset);
        } catch (NumberFormatException | DateTimeException e) {
            return false;
        }
        return true;
    };
}