List of usage examples for java.time LocalDateTime atZone
@Override
public ZonedDateTime atZone(ZoneId zone)
From source file:fr.pilato.elasticsearch.crawler.fs.framework.FsCrawlerUtil.java
public static Date localDateTimeToDate(LocalDateTime ldt) { return Date.from(ldt.atZone(TimeZone.getDefault().toZoneId()).toInstant()); }
From source file:com.epam.parso.impl.CSVDataWriterImpl.java
/** * The function to convert a Java 8 LocalDateTime into a string according to the format used. * * @param currentDate the LocalDateTime to convert. * @param format the string with the format that must belong to the set of * {@link CSVDataWriterImpl#DATE_OUTPUT_FORMAT_STRINGS} mapping keys. * @return the string that corresponds to the date in the format used. *//*from ww w .j a va 2 s . co m*/ protected static String convertLocalDateTimeElementToString(LocalDateTime currentDate, String format) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_OUTPUT_FORMAT_STRINGS.get(format)); String valueToPrint = ""; ZonedDateTime zonedDateTime = currentDate.atZone(ZoneOffset.UTC); if (zonedDateTime.toInstant().toEpochMilli() != 0 && zonedDateTime.getNano() != 0) { valueToPrint = formatter.format(currentDate); } return valueToPrint; }
From source file:net.ceos.project.poi.annotated.core.CellFormulaHandler.java
/** * Apply a Date value to the cell.// ww w . ja va 2 s . c om * * @param configCriteria * the {@link XConfigCriteria} * @param object * the object * @param cell * the {@link Cell} to use * @throws IllegalAccessException * @throws ConverterException */ protected static void localDateTimeHandler(final XConfigCriteria configCriteria, final Object object, final Cell cell) throws IllegalAccessException, ConverterException { LocalDateTime date = (LocalDateTime) configCriteria.getField().get(object); if (StringUtils.isNotBlank(configCriteria.getElement().transformMask())) { // apply transformation mask String decorator = configCriteria.getElement().transformMask(); convertDate(cell, Date.from(date.atZone(ZoneId.systemDefault()).toInstant()), decorator); } else if (StringUtils.isNotBlank(configCriteria.getElement().formatMask())) { // apply format mask CellValueHandler.consumeValue(cell, Date.from(date.atZone(ZoneId.systemDefault()).toInstant())); } else { // apply default date mask CellValueHandler.consumeValue(cell, Date.from(date.atZone(ZoneId.systemDefault()).toInstant())); } }
From source file:com.tascape.reactor.report.MySqlBaseBean.java
public static long getMillis(String time) { if (time == null || time.trim().isEmpty()) { return System.currentTimeMillis(); } else {// w w w. j a va 2 s. c o m LocalDateTime ldt = LocalDateTime.parse(time, DateTimeFormatter.ISO_LOCAL_DATE_TIME); LOG.trace("ldt {}", ldt); ZoneId zone = ZoneId.of("America/Los_Angeles"); ldt.atZone(zone); LOG.trace("ldt {}", ldt); return ldt.toInstant(ZoneOffset.ofHours(-8)).toEpochMilli(); } }
From source file:fi.helsinki.opintoni.service.TimeService.java
public LocalDateTime endOfDayHelsinki(LocalDateTime fromLocalDateTime) { ZonedDateTime zonedDateTime = fromLocalDateTime.atZone(HELSINKI_ZONE_ID).withHour(23).withMinute(59) .withSecond(59);//w w w. ja v a 2 s .co m return LocalDateTime.ofInstant(zonedDateTime.toInstant(), ZoneId.of("UTC")); }
From source file:eu.off.db.entity.MemberTest.java
@Test public void BuildFullMember() { LocalDateTime dateTime = LocalDateTime.of(1978, Month.APRIL, 4, 0, 0); Date birthday = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant()); Member aMember = new MemberBuilder(LAST_NAME, FIRST_NAME, STREET, ZIP_CODE, PLACE, COUNTRY, birthday, GENDER, NATIONALITY).email(EMAIL).phone(PHONE).portablePhone(PORTABLE_PHONE).memberSince(birthday) .licenseSince(birthday).build(); assertThat(aMember.getEmail().equals(EMAIL)); assertThat(aMember.getPhone().equals(PHONE)); assertThat(aMember.getPortablePhone().equals(PORTABLE_PHONE)); assertThat(aMember.getMemberSince().equals(birthday)); assertThat(aMember.getLicenseSince().equals(birthday)); }
From source file:eu.off.db.entity.MemberTest.java
@Test public void BuildMinimalMember() { LocalDateTime dateTime = LocalDateTime.of(1978, Month.APRIL, 4, 0, 0); Date birthday = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant()); Member aMember = new MemberBuilder(LAST_NAME, FIRST_NAME, STREET, ZIP_CODE, PLACE, COUNTRY, birthday, GENDER, NATIONALITY).build(); assertThat(aMember.getLastName().equals(LAST_NAME)); assertThat(aMember.getFirstName().equals(FIRST_NAME)); assertThat(aMember.getAdress().equals(STREET)); assertThat(aMember.getZipCode().equals(ZIP_CODE)); assertThat(aMember.getPlace().equals(PLACE)); assertThat(aMember.getCountry().equals(COUNTRY)); assertThat(aMember.getBirthday().equals(birthday)); assertThat(aMember.getGender().equals(GENDER)); assertThat(aMember.getNationality().equals(NATIONALITY)); }
From source file:com.gigglinggnus.controllers.AdminClockController.java
/** * * @param request servlet request/*from w w w . ja va2s .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 strTime = request.getParameter("systemTime"); LocalDateTime ldTime = LocalDateTime.parse(strTime); Instant instant = ldTime.atZone(ZoneId.systemDefault()).toInstant(); Clock clk = Clock.fixed(instant, ZoneId.systemDefault()); request.getSession().setAttribute("clock", clk); RequestDispatcher rd = request.getRequestDispatcher("/home.jsp"); rd.forward(request, response); }
From source file:com.onyxscheduler.OnyxSchedulerIT.java
private Date toDate(LocalDateTime localDateTime) { return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); }
From source file:me.rkfg.xmpp.bot.plugins.FaggotOfTheDayPlugin.java
private Date getFirstTime() { final LocalTime midnight = LocalTime.MIDNIGHT; final LocalDate today = LocalDate.now(); final LocalDateTime todayMidnight = LocalDateTime.of(today, midnight); return Date.from(todayMidnight.atZone(ZoneId.systemDefault()).toInstant()); }