Example usage for java.time.format DateTimeFormatter ofPattern

List of usage examples for java.time.format DateTimeFormatter ofPattern

Introduction

In this page you can find the example usage for java.time.format DateTimeFormatter ofPattern.

Prototype

public static DateTimeFormatter ofPattern(String pattern) 

Source Link

Document

Creates a formatter using the specified pattern.

Usage

From source file:com.qq.tars.service.monitor.TARSPropertyMonitorCondition.java

public TARSPropertyMonitorCondition(HttpServletRequest request) {
    thedate = StringUtils.trimToNull(request.getParameter("thedate"));
    predate = StringUtils.trimToNull(request.getParameter("predate"));
    theshowtime = StringUtils.trimToNull(request.getParameter("theshowtime"));
    preshowtime = StringUtils.trimToNull(request.getParameter("preshowtime"));

    masterName = StringUtils.trimToNull(request.getParameter("master_name"));
    masterIp = StringUtils.trimToNull(request.getParameter("master_ip"));
    propertyName = StringUtils.trimToNull(request.getParameter("property_name"));
    policy = StringUtils.trimToNull(request.getParameter("policy"));

    groupBy = StringUtils.trimToNull(request.getParameter("group_by"));

    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
    if (null == thedate) {
        thedate = LocalDate.now().format(formatter);
    }//  w  w w. j  ava2 s .c  o m
    if (null == predate) {
        predate = LocalDate.parse(thedate, formatter).plusDays(-1).format(formatter);
    }
    if (null == theshowtime) {
        theshowtime = "0000";
    }
    if (null == preshowtime) {
        preshowtime = "2360";
    }
}

From source file:org.codelibs.fess.service.ClickLogService.java

public void importCsv(final Reader reader) {
    final CsvReader csvReader = new CsvReader(reader, new CsvConfig());
    final DateTimeFormatter formatter = DateTimeFormatter
            .ofPattern(CoreLibConstants.DATE_FORMAT_ISO_8601_EXTEND);
    try {//from  ww w.  ja  va  2s.  c o m
        List<String> list;
        csvReader.readValues(); // ignore header
        while ((list = csvReader.readValues()) != null) {
            try {
                final String dateStr = list.get(3);
                final String userSessionId = list.get(4);
                final SearchLog searchLog = searchLogBhv.selectEntity(cb -> {
                    cb.query().setRequestedTime_Equal(LocalDateTime.parse(dateStr, formatter));
                    cb.query().setUserSessionId_Equal(userSessionId);
                }).orElse(null);//TODO
                if (searchLog != null) {
                    final ClickLog entity = new ClickLog();
                    entity.setId(Long.parseLong(list.get(0)));
                    entity.setSearchId(searchLog.getId());
                    entity.setUrl(list.get(1));
                    entity.setRequestedTime(LocalDateTime.parse(list.get(2), formatter));
                    clickLogBhv.insert(entity);
                } else {
                    log.warn("The search log is not found: " + list);
                }
            } catch (final Exception e) {
                log.warn("Failed to read a click log: " + list, e);
            }
        }
    } catch (final IOException e) {
        log.warn("Failed to read a click log.", e);
    }
}

From source file:com.qq.tars.service.monitor.TARSStatMonitorCondition.java

public TARSStatMonitorCondition(HttpServletRequest request) {
    thedate = StringUtils.trimToNull(request.getParameter("thedate"));
    predate = StringUtils.trimToNull(request.getParameter("predate"));
    theshowtime = StringUtils.trimToNull(request.getParameter("theshowtime"));
    preshowtime = StringUtils.trimToNull(request.getParameter("preshowtime"));

    masterName = StringUtils.trimToNull(request.getParameter("master_name"));
    slaveName = StringUtils.trimToNull(request.getParameter("slave_name"));
    interfaceName = StringUtils.trimToNull(request.getParameter("interface_name"));
    masterIp = StringUtils.trimToNull(request.getParameter("master_ip"));
    slaveIp = StringUtils.trimToNull(request.getParameter("slave_ip"));

    groupBy = StringUtils.trimToNull(request.getParameter("group_by"));

    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
    if (null == thedate) {
        thedate = LocalDate.now().format(formatter);
    }//from w  w w  . j  a v  a 2  s  . c om
    if (null == predate) {
        predate = LocalDate.parse(thedate, formatter).plusDays(-1).format(formatter);
    }
    if (null == theshowtime) {
        theshowtime = "0000";
    }
    if (null == preshowtime) {
        preshowtime = "2360";
    }
}

From source file:fi.csc.emrex.smp.model.Person.java

public void setBirthDate(String birthDate, String dateFormat) {
    dateFormatter = DateTimeFormatter.ofPattern(dateFormat);
    if (birthDate == null || dateFormat == null) {
        this.birthDate = null;
    } else {//from w w w.j a v a 2  s .c  o m
        this.birthDate = LocalDate.parse(birthDate, dateFormatter);
    }
}

From source file:org.openlmis.converter.DirectDateTypeConverter.java

private String parseDate(String value) {
    LocalDate date = null;/*  w ww  .j  a v  a2  s .  c o  m*/

    for (String format : DATE_FORMATS) {
        try {
            date = LocalDate.parse(value, DateTimeFormatter.ofPattern(format));
            break;
        } catch (DateTimeParseException exp) {
            date = null;
            logger.debug("Can't parse date {} with format {}", value, format, exp);
        }
    }

    return null == date ? null : date.format(DateTimeFormatter.ISO_DATE);
}

From source file:com.qq.tars.service.PatchService.java

@Transactional(rollbackFor = Exception.class)
public ServerPatch addServerPatch(String application, String moduleName, String tgz, String comment) {
    String md5 = md5(tgz);//from w w w  . j  a v a 2 s .com
    Preconditions.checkNotNull(md5);

    ServerPatch patch = new ServerPatch();
    patch.setServer(String.format("%s.%s", application, moduleName));
    patch.setTgz(FilenameUtils.getName(tgz));
    patch.setMd5(md5);
    patch.setUpdateText(comment);
    patch.setPosttime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

    patchMapper.insertServerPatch(patch);
    log.info("id={}, server={}, tgz={}, md5={}, update_text={}", patch.getId(), patch.getServer(),
            patch.getTgz(), patch.getMd5(), patch.getUpdateText());
    return patch;
}

From source file:com.example.securelogin.app.welcome.HomeController.java

/**
 * Simply selects the home view to render by returning its name.
 *//*from   www. j  a  v a 2 s.c  o  m*/
@RequestMapping(value = "/", method = { RequestMethod.GET, RequestMethod.POST })
public String home(@AuthenticationPrincipal LoggedInUser userDetails, Model model) {

    Account account = userDetails.getAccount();

    model.addAttribute("account", account);

    if (accountSharedService.isCurrentPasswordExpired(account.getUsername())) {
        ResultMessages messages = ResultMessages.warning().add("w.sl.pe.0001");
        model.addAttribute(messages);
    }

    LocalDateTime lastLoginDate = userDetails.getLastLoginDate();
    if (lastLoginDate != null) {
        model.addAttribute("lastLoginDate",
                lastLoginDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    }

    return "welcome/home";

}

From source file:svc.data.citations.datasources.mock.MockCitationDataSourceIntegrationTest.java

@Test
public void GetCitationsByDOBAndLastNameAndMunicipalitiesSuccessful() throws ParseException {
    String dateString = "05/18/1987";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
    LocalDate date = LocalDate.parse(dateString, formatter);

    List<Long> municipalities = Lists.newArrayList(33L, 44L);

    List<Citation> citations = mockCitationDataSource.getByNameAndMunicipalitiesAndDOB("Peterson",
            municipalities, date);/* w  w w.ja  v  a  2s  .  c o m*/
    assertThat(citations, is(notNullValue()));
    assertThat(citations.size(), is(2));
    assertThat(citations.get(0).first_name, is("Brenda"));
}

From source file:io.gravitee.repository.elasticsearch.monitoring.ElasticMonitoringRepository.java

@Override
public MonitoringResponse query(final String gatewayId) {
    final String suffixDay = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd"));

    final SearchRequestBuilder monitor = client.prepareSearch("gravitee-" + suffixDay).setTypes("monitor")
            .setQuery(boolQuery().must(termQuery(FIELD_GATEWAY_NAME, gatewayId)))
            .setSearchType(SearchType.QUERY_THEN_FETCH).addSort(FIELD_TIMESTAMP, SortOrder.DESC).setSize(1);

    final SearchResponse searchResponse = monitor.get();
    final SearchHits hits = searchResponse.getHits();
    if (hits != null && hits.getHits().length > 0) {
        return convert(hits.getHits()[0].getSource());
    }//w ww  . ja  v a 2 s.  c o  m
    return null;
}

From source file:org.jbb.members.web.base.logic.MemberSearchCriteriaFactory.java

private LocalDate getJoinDate(SearchMemberForm form) {
    try {/*from  www.  j av  a  2  s .  c  o  m*/
        return StringUtils.isNotBlank(form.getJoinedDate())
                ? LocalDate.parse(form.getJoinedDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd"))
                : null;
    } catch (DateTimeParseException e) {
        log.trace("Date time parsing error", e);
        throw new MemberSearchJoinDateFormatException();
    }
}