List of usage examples for java.time ZonedDateTime of
public static ZonedDateTime of(LocalDate date, LocalTime time, ZoneId zone)
From source file:Main.java
public static void main(String[] args) { ZonedDateTime z = ZonedDateTime.of(LocalDate.now(), LocalTime.now(), ZoneId.systemDefault()); System.out.println(z);/*from ww w .j a va 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { LocalDate localDate = LocalDate.of(2013, 11, 12); LocalTime localTime = LocalTime.of(23, 10, 44, 12882); ZoneId chicago = ZoneId.of("America/Chicago"); ZonedDateTime chicagoTime = ZonedDateTime.of(localDate, localTime, chicago); System.out.println(chicagoTime); }
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:fixio.netty.codec.FixMessageDecoderTest.java
@Test public void testDecode() throws Exception { List<Object> result = decode( "8=FIX.4.1\u00019=90\u000135=0\u000149=INVMGR\u000156=BRKR\u000134=240\u000152=19980604-08:03:31\u000110=129\u0001"); assertEquals(1, result.size());//from ww w. j a va 2 s. com assertTrue(result.get(0) instanceof FixMessageImpl); final FixMessageImpl fixMessage = (FixMessageImpl) result.get(0); FixMessageHeader header = fixMessage.getHeader(); assertEquals("FIX.4.1", fixMessage.getHeader().getBeginString()); assertEquals(MessageTypes.HEARTBEAT, fixMessage.getMessageType()); assertEquals("INVMGR", header.getSenderCompID()); assertEquals("BRKR", header.getTargetCompID()); assertEquals(240, header.getMsgSeqNum()); assertEquals(129, fixMessage.getChecksum()); final Long value = fixMessage.getValue(FieldType.SendingTime); assertEquals(ZonedDateTime.of(LocalDate.of(1998, 6, 4), LocalTime.of(8, 3, 31), systemUTC().zone()) .toInstant().toEpochMilli(), value.longValue()); }
From source file:msi.gama.util.GamaDate.java
public GamaDate(final IScope scope, final Temporal d) { final ZoneId zone; if (d instanceof ChronoZonedDateTime) { zone = ZonedDateTime.from(d).getZone(); } else if (d.isSupported(ChronoField.OFFSET_SECONDS)) { zone = ZoneId.ofOffset("", ZoneOffset.ofTotalSeconds(d.get(ChronoField.OFFSET_SECONDS))); } else {/*from w ww. j a va 2s . c o m*/ zone = GamaDateType.DEFAULT_ZONE; } if (!d.isSupported(MINUTE_OF_HOUR)) { internal = ZonedDateTime.of(LocalDate.from(d), LocalTime.of(0, 0), zone); } else if (!d.isSupported(DAY_OF_MONTH)) { internal = ZonedDateTime.of(LocalDate.from( scope == null ? Dates.DATES_STARTING_DATE.getValue() : scope.getSimulation().getStartingDate()), LocalTime.from(d), zone); } else { internal = d; } }
From source file:objective.taskboard.controller.FollowUpController.java
private String templateDate(Optional<LocalDate> date, ZoneId timezone) { return date.map(d -> ZonedDateTime.of(d, LocalTime.MIDNIGHT, timezone)).orElse(ZonedDateTime.now(timezone)) .format(formatter);//from w w w .j ava 2 s .com }
From source file:com.gigglinggnus.controllers.StudentMakeAppointmentController.java
/** * * @param request servlet request//ww w .j a v a 2 s.co 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 w w. j a v a 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:org.dbflute.solr.cbean.SolrQueryBuilder.java
public static String queryBuilderForRangeSearch(String solrFieldName, LocalDate from, LocalDate to) { Date fromDate = from == null ? null : Date.from(ZonedDateTime.of(from, LocalTime.MIDNIGHT, ZoneId.systemDefault()).toInstant()); Date toDate = to == null ? null : Date.from(ZonedDateTime.of(to, LocalTime.MIDNIGHT, ZoneId.systemDefault()).toInstant()); return queryBuilderForRangeSearch(solrFieldName, fromDate, toDate); }