Example usage for java.time LocalTime toString

List of usage examples for java.time LocalTime toString

Introduction

In this page you can find the example usage for java.time LocalTime toString.

Prototype

@Override
public String toString() 

Source Link

Document

Outputs this time as a String , such as 10:15 .

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalTime l = LocalTime.now();

    System.out.println(l.toString());
}

From source file:de.msg.service.RouteService.java

public String formatTime(LocalTime time) {
    return time.toString();
}

From source file:com.gigglinggnus.controllers.StudentMakeAppointmentController.java

/**
 *
 * @param request servlet request//from  ww w .  j a v a2 s .c  o  m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    EntityManager em = (EntityManager) request.getSession().getAttribute("em");

    String msg = request.getParameter("msg");
    User user = (User) (request.getSession().getAttribute("user"));
    Clock clk = (Clock) (request.getSession().getAttribute("clock"));

    if (msg.equals("lookup_student")) {
        String studId = request.getParameter("studentId");
        List<Exam> exams = user.getRegistrableExams();
        JSONObject json = new JSONObject();
        json.put("students_idNumber", studId);
        json.put("firstName", user.getFirstName());
        json.put("lastName", user.getLastName());
        JSONArray jExams = new JSONArray();
        for (Exam exam : exams) {
            JSONObject elem = new JSONObject();

            String examId = exam.getExamId();
            String termId = exam.getTerm().getTermId();
            String start = exam.getInterval().getStart().atZone(ZoneId.systemDefault()).toLocalDate()
                    .toString();
            String end = exam.getInterval().getEnd().atZone(ZoneId.systemDefault()).toLocalDate().toString();
            elem.put("examId", examId);
            elem.put("termId", termId);
            if (exam instanceof CourseExam) {
                String courseId = ((CourseExam) exam).getCourse().getCourseId();
                elem.put("courseId", courseId);
                elem.put("examType", "Course");
            } else {
                elem.put("courseId", "N/A");
                elem.put("examType", "AdHoc");
            }
            elem.put("start", start);
            elem.put("end", end);
            jExams.put(elem);
        }
        json.put("exams", jExams);
        response.getWriter().write(json.toString());
    } else if (msg.equals("exam_available_timeslots")) {
        String examId = request.getParameter("examId");
        String dateStr = request.getParameter("date");
        Exam exam = em.find(Exam.class, examId);
        LocalDate apptDate = LocalDate.parse(dateStr);
        List<LocalTime> timeslots = exam.getTimeslotsForDay(apptDate);

        JSONObject json = new JSONObject();
        json.put("examId", examId);
        JSONArray jTimeSlots = new JSONArray();
        for (LocalTime timeslot : timeslots) {
            String start = timeslot.toString();
            String end = timeslot.plus(exam.getDuration()).toString();
            JSONObject elem = new JSONObject();
            elem.put("start", start);
            elem.put("end", end);
            jTimeSlots.put(elem);
        }
        json.put("timeSlots", jTimeSlots);
        response.getWriter().write(json.toString());
    } else if (msg.equals("submit-appointment")) {
        String studId = request.getParameter("studentId");
        String examId = request.getParameter("examId");
        String stDate = request.getParameter("examDate");
        String stTime = request.getParameter("startTime") + ":00";
        String stSeat = request.getParameter("seatType");

        Exam exam = em.find(Exam.class, examId);
        LocalDate lDate = LocalDate.parse(stDate);
        LocalTime lTime = LocalTime.parse(stTime);
        Instant inst = ZonedDateTime.of(lDate, lTime, ZoneId.systemDefault()).toInstant();
        JSONObject json = new JSONObject();
        try {
            em.getTransaction().begin();
            user.makeAppointment(exam, inst, clk);
            em.getTransaction().commit();
            json.put("success", "Appointment Made!");
            response.getWriter().write(json.toString());
        } catch (Exception e) {
            em.getTransaction().rollback();
            json.put("error", e.toString());
            response.getWriter().write(json.toString());
        }
    } else {
        JSONObject json = new JSONObject();
        json.put("error", msg);
        response.getWriter().write(json.toString());
    }
}

From source file:com.gigglinggnus.controllers.AdminMakeAppointmentController.java

/**
 *
 * @param request servlet request/* w  ww .java 2  s  .  c o m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    EntityManager em = (EntityManager) request.getSession().getAttribute("em");

    String msg = request.getParameter("msg");
    User user = (User) (request.getSession().getAttribute("user"));
    Clock clk = (Clock) (request.getSession().getAttribute("clock"));

    if (msg.equals("lookup_student")) {
        String studId = request.getParameter("studentId");
        User student = em.find(User.class, studId);
        List<Exam> exams = student.getRegistrableExams();
        JSONObject json = new JSONObject();
        json.put("students_idNumber", studId);
        json.put("firstName", student.getFirstName());
        json.put("lastName", student.getLastName());
        JSONArray jExams = new JSONArray();
        for (Exam exam : exams) {
            JSONObject elem = new JSONObject();

            String examId = exam.getExamId();
            String termId = exam.getTerm().getTermId();
            String start = exam.getInterval().getStart().atZone(ZoneId.systemDefault()).toLocalDate()
                    .toString();
            String end = exam.getInterval().getEnd().atZone(ZoneId.systemDefault()).toLocalDate().toString();
            elem.put("examId", examId);
            elem.put("termId", termId);
            if (exam instanceof CourseExam) {
                String courseId = ((CourseExam) exam).getCourse().getCourseId();
                elem.put("courseId", courseId);
                elem.put("examType", "Course");
            } else {
                elem.put("courseId", "N/A");
                elem.put("examType", "AdHoc");
            }
            elem.put("start", start);
            elem.put("end", end);
            jExams.put(elem);
        }
        json.put("exams", jExams);
        response.getWriter().write(json.toString());
    } else if (msg.equals("exam_available_timeslots")) {
        String examId = request.getParameter("examId");
        String dateStr = request.getParameter("date");
        Exam exam = em.find(Exam.class, examId);
        LocalDate apptDate = LocalDate.parse(dateStr);
        List<LocalTime> timeslots = exam.getTimeslotsForDay(apptDate);

        JSONObject json = new JSONObject();
        json.put("examId", examId);
        JSONArray jTimeSlots = new JSONArray();
        for (LocalTime timeslot : timeslots) {
            String start = timeslot.toString();
            String end = timeslot.plus(exam.getDuration()).toString();
            JSONObject elem = new JSONObject();
            elem.put("start", start);
            elem.put("end", end);
            jTimeSlots.put(elem);
        }
        json.put("timeSlots", jTimeSlots);
        response.getWriter().write(json.toString());
    } else if (msg.equals("submit-appointment")) {
        String studId = request.getParameter("studentId");
        String examId = request.getParameter("examId");
        String stDate = request.getParameter("examDate");
        String stTime = request.getParameter("startTime") + ":00";
        String stSeat = request.getParameter("seatType");

        User student = em.find(User.class, studId);
        Exam exam = em.find(Exam.class, examId);
        LocalDate lDate = LocalDate.parse(stDate);
        LocalTime lTime = LocalTime.parse(stTime);
        Instant inst = ZonedDateTime.of(lDate, lTime, ZoneId.systemDefault()).toInstant();
        JSONObject json = new JSONObject();
        try {
            em.getTransaction().begin();
            if (stSeat.equals("normal")) {
                user.makeAppointment(student, Seating.NORMAL, exam, inst, clk);
                em.getTransaction().commit();
                json.put("success", "Appointment Made!");
                response.getWriter().write(json.toString());
            } else if (stSeat.equals("setaside")) {
                user.makeAppointment(student, Seating.SETASIDE, exam, inst, clk);
                em.getTransaction().commit();
                json.put("success", "Appointment Made!");
                response.getWriter().write(json.toString());
            } else {
                em.getTransaction().rollback();
                json.put("error", "invalid choice of seating");
                response.getWriter().write(json.toString());
            }
        } catch (Exception e) {
            em.getTransaction().rollback();
            json.put("error", e.toString());
            response.getWriter().write(json.toString());
        }
    } else {
        JSONObject json = new JSONObject();
        json.put("error", msg);
        response.getWriter().write(json.toString());
    }
}

From source file:dhbw.clippinggorilla.objects.user.UserUtils.java

/**
 * Adds a new Clipping sending time for a User
 *
 * @param u The User of the new Clipping sending time
 * @param time The Time of the clipping being send
 * @return true if successful, false otherwise
 *//*from   ww w  .  java 2 s .c om*/
public static boolean addClippingSendTime(User u, LocalTime time) {
    try {
        String sql = "INSERT INTO " + Tables.USER_CLIPPING_TIMES + " (" + Columns.USER_ID + ", "
                + Columns.CLIPPING_TIME + ") VALUES (?, ?)";
        PreparedStatement statement = Database.getConnection().prepareStatement(sql);
        statement.setInt(1, u.getId());
        statement.setString(2, time.toString());
        statement.executeUpdate();
    } catch (SQLException ex) {
        Log.warning("Sql failed: addClippingTime", ex);
        return false;
    }
    u.getClippingTime().add(time);
    Jobs.updateClippingGenerationTimes(u, u.getClippingTime());
    return true;
}

From source file:dhbw.clippinggorilla.objects.user.UserUtils.java

/**
 * removes a clipping send time from the users set.
 *
 * @param u The User which Clipping sending time should be removed
 * @param time time to remove, has to be in the users ClippingSendTimes!
 * @return true if successful//  w w w.  jav  a  2s.  co  m
 */
public static boolean removeClippingSendTime(User u, LocalTime time) {
    if (u.getClippingTime().contains(time)) {
        String sql = "DELETE FROM " + Tables.USER_CLIPPING_TIMES + " WHERE " + Columns.USER_ID + " = ? AND "
                + Columns.CLIPPING_TIME + " = ?";
        try {
            PreparedStatement statement = Database.getConnection().prepareStatement(sql);
            statement.setInt(1, u.getId());
            statement.setString(2, time.toString());
            statement.executeUpdate();
        } catch (SQLException ex) {
            Log.warning("Sql failed: deleteClippingTime", ex);
            return false;
        }
        u.getClippingTime().remove(time);
        Jobs.updateClippingGenerationTimes(u, u.getClippingTime());
        return true;
    }
    return false;
}