Example usage for java.time LocalDateTime atZone

List of usage examples for java.time LocalDateTime atZone

Introduction

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

Prototype

@Override
public ZonedDateTime atZone(ZoneId zone) 

Source Link

Document

Combines this date-time with a time-zone to create a ZonedDateTime .

Usage

From source file:scouterx.webapp.request.SummaryRequest.java

private void setTimeAsYmd() {
    ZoneId zoneId = ZoneId.systemDefault();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmm");
    LocalDateTime startDateTime = LocalDateTime.parse(startYmdHm, formatter);
    LocalDateTime endDateTime = LocalDateTime.parse(endYmdHm, formatter);

    startTimeMillis = startDateTime.atZone(zoneId).toEpochSecond() * 1000L;
    endTimeMillis = endDateTime.atZone(zoneId).toEpochSecond() * 1000L;
}

From source file:scouterx.webapp.request.CounterRequestByType.java

private void setTimeAsYmd() {
    ZoneId zoneId = ZoneId.systemDefault();
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
    LocalDateTime startDateTime = LocalDateTime.parse(startYmdHms, formatter);
    LocalDateTime endDateTime = LocalDateTime.parse(endYmdHms, formatter);

    startTimeMillis = startDateTime.atZone(zoneId).toEpochSecond() * 1000L;
    endTimeMillis = endDateTime.atZone(zoneId).toEpochSecond() * 1000L;
}

From source file:at.becast.youploader.youtube.GuiUploadEvent.java

@Override
public void onInit() {
    this.starttime = System.currentTimeMillis();
    this.lastdata = 0;
    this.lasttime = this.starttime;
    this.lastdb = this.starttime;
    Date in = new Date(this.starttime);
    LocalDateTime ldt = LocalDateTime.ofInstant(in.toInstant(), ZoneId.systemDefault());
    Date out = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant());
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT,
            Locale.getDefault());
    frame.getlblStart().setText(formatter.format(out));
    frame.getProgressBar().setString("0,00 %");
    frame.getProgressBar().setValue(0);//from   w  ww.  j a v  a  2s.  c  o m
    frame.getProgressBar().revalidate();
    frame.getBtnCancel().setEnabled(true);
    frame.getBtnEdit().setEnabled(true);
    frame.getBtnDelete().setEnabled(false);
    frame.revalidate();
    frame.repaint();
}

From source file:org.millr.slick.servlets.item.EditItemServlet.java

private Date convertDate(String publishString) {

    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm", Locale.ENGLISH);
    LocalDateTime dateTime = LocalDateTime.parse(publishString, formatter);

    Date publishDate = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());

    return publishDate;
}

From source file:fi.vrk.xroad.catalog.lister.JaxbConverter.java

protected XMLGregorianCalendar toXmlGregorianCalendar(LocalDateTime localDateTime) {
    if (localDateTime == null) {
        return null;
    } else {/*  w ww. ja  va  2 s  .  c o  m*/
        GregorianCalendar cal = GregorianCalendar.from(localDateTime.atZone(ZoneId.systemDefault()));
        XMLGregorianCalendar xc = null;
        try {
            xc = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
        } catch (DatatypeConfigurationException e) {
            throw new CatalogListerRuntimeException("Cannot instantiate DatatypeFactory", e);
        }
        return xc;
    }
}

From source file:net.ceos.project.poi.annotated.core.CsvHandler.java

/**
 * Apply a date time value at the field.
 * //from   w w w. j  a  v a 2  s .  co  m
 * @param value
 *            the value
 * @param formatMask
 *            the decorator mask
 * @param transformMask
 *            the transformation mask
 * @return false if problem otherwise true
 * @throws ConverterException
 *             the conversion exception type
 */
protected static String toLocalDateTime(final LocalDateTime value, final String formatMask,
        final String transformMask) throws ConverterException {
    String dateMasked = StringUtils.EMPTY;
    if (value != null) {
        try {
            if (StringUtils.isNotBlank(transformMask)) {
                // apply transformation mask
                dateMasked = applyMaskToDate(Date.from(value.atZone(ZoneId.systemDefault()).toInstant()),
                        transformMask);

            } else if (StringUtils.isNotBlank(formatMask)) {
                // apply format mask
                dateMasked = applyMaskToDate(Date.from(value.atZone(ZoneId.systemDefault()).toInstant()),
                        formatMask);

            } else {
                // default mask
                dateMasked = applyMaskToDate(Date.from(value.atZone(ZoneId.systemDefault()).toInstant()),
                        Constants.DD_MMM_YYYY_HH_MM_SS);
            }
        } catch (Exception e) {
            throw new ConverterException(ExceptionMessage.CONVERTER_LOCALDATETIME.getMessage(), e);
        }
    }
    return dateMasked;
}

From source file:cn.edu.zjnu.acm.judge.admin.AdminController.java

@PostMapping("/admin/contests")
public String addContest(@RequestParam(value = "title", required = false) String title,
        @RequestParam(value = "description", required = false) String description,
        @RequestParam(value = "start") @DateTimeFormat(pattern = "yyyy-M-d H:m") LocalDateTime start,
        @RequestParam("length") @Pattern(regexp = "\\d+:[0-5]?[0-9]:[0-5]?[0-9]") String length, Model model) {
    Instant startTime = start.atZone(ZoneId.systemDefault()).toInstant();
    String[] split = length.split(":", 3);
    long h = Long.parseLong(split[0]);
    int m = Integer.parseInt(split[1]);
    int s = Integer.parseInt(split[2]);
    Instant endTime = startTime.plusSeconds(h * 3600 + m * 60 + s);

    Contest contest = Contest.builder().title(title).description(description).startTime(startTime)
            .endTime(endTime).build();//w  w  w.  ja v  a 2s  . c  o  m
    contestMapper.save(contest);

    model.addAttribute("contestId", contest.getId());
    model.addAttribute("startTime", startTime);
    model.addAttribute("endTime", endTime);

    return "admin/contests/add";
}

From source file:com.bdb.weather.display.stripchart.StripChart.java

/**
 * Add an item to a series.//from   w w w. j  a  va  2 s  .  c om
 * 
 * @param seriesName The name of the series to which the data is to be added
 * @param time The time of the data
 * @param value The value of the data
 */
public void addItem(String seriesName, LocalDateTime time, double value) {
    TimeSeries timeSeries = series.get(seriesName);
    Instant instant = Instant.from(time.atZone(ZoneId.systemDefault()));
    Date res = Date.from(instant);

    if (timeSeries != null) {
        timeSeries.removeAgedItems(false);
        timeSeries.addOrUpdate(new Second(res), value);
        Calendar c = Calendar.getInstance();
        c.setTime(res);
        adjustDateAxis(c);
    }
}

From source file:org.apdplat.superword.system.AntiRobotFilter.java

public void init(FilterConfig config) throws ServletException {
    int initialDelay = 24 - LocalDateTime.now().getHour();
    scheduledExecutorService.scheduleAtFixedRate(() -> {
        try {/*from  w w  w  .  java2 s  .  c  o  m*/
            LOG.info("clear last day anti-robot counter");
            LocalDateTime timePoint = LocalDateTime.now().minusDays(1);
            String date = SIMPLE_DATE_FORMAT
                    .format(Date.from(timePoint.atZone(ZoneId.systemDefault()).toInstant()));
            Map<String, Integer> archive = new HashMap<String, Integer>();
            Enumeration<String> keys = servletContext.getAttributeNames();
            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                if (key.startsWith("anti-robot-") && key.endsWith(date)) {
                    archive.put(key, ((AtomicInteger) servletContext.getAttribute(key)).intValue());
                }
            }
            archive.keySet().forEach(servletContext::removeAttribute);
            File path = new File(servletContext.getRealPath("/WEB-INF/data/anti-robot-archive/"));
            if (!path.exists()) {
                path.mkdirs();
            }
            String file = path.getPath() + "/" + date + "__user_agent_invalid_count_" + invalidCount + ".txt";
            Files.write(Paths.get(file), archive.entrySet().stream()
                    .map(e -> e.getKey().replace("anti-robot-", "").replace("-", "\t") + "\t" + e.getValue())
                    .map(line -> {
                        String[] attrs = line.split("\\s+");
                        String location = "";
                        if (attrs != null && attrs.length > 1) {
                            String ip = attrs[1];
                            location = IPUtils.getIPLocation(ip).toString();
                        }
                        return line + "\t" + location;
                    }).collect(Collectors.toList()));
            invalidCount = 0;
            LOG.info("clear last day anti-robot counter finished: " + file);
        } catch (Exception e) {
            LOG.error("save anti-robot-archive failed", e);
        }
    }, initialDelay, 24, TimeUnit.HOURS);
}

From source file:com.orange.clara.cloud.servicedbdumper.task.job.JobFactoryTest.java

@Test
public void when_purge_errored_jobs_and_jobs_in_error_exist_it_should_delete_job_which_pass_expiration() {
    Job jobNotExpired = new Job();
    jobNotExpired.setUpdatedAt(new Date());

    Date date = new Date();
    LocalDateTime localDateTime = LocalDateTime.from(date.toInstant().atZone(ZoneId.systemDefault()))
            .minusDays(jobErroredDeleteExpirationDays + 1);
    Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
    Job jobExpired = new Job();
    jobExpired.setUpdatedAt(Date.from(instant));

    when(jobRepo.findByJobEventOrderByUpdatedAtDesc(anyObject()))
            .thenReturn(Arrays.asList(jobNotExpired, jobExpired));
    jobFactory.purgeErroredJobs();/*  w  w  w . j a va 2  s.  co  m*/
    verify(jobRepo, times(1)).delete((Job) notNull());
}