Example usage for java.time LocalDateTime format

List of usage examples for java.time LocalDateTime format

Introduction

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

Prototype

@Override 
public String format(DateTimeFormatter formatter) 

Source Link

Document

Formats this date-time using the specified formatter.

Usage

From source file:lumbermill.internal.aws.AWSV4SignerImpl.java

private byte[] getSignatureKey(LocalDateTime now, AWSCredentials credentials) {
    final byte[] kSecret = (AWS4 + credentials.getAWSSecretKey()).getBytes(Charsets.UTF_8);
    final byte[] kDate = hmacSHA256(now.format(DateTimeFormatter.BASIC_ISO_DATE), kSecret);
    final byte[] kRegion = hmacSHA256(region, kDate);
    final byte[] kService = hmacSHA256(service, kRegion);
    return hmacSHA256(AWS_4_REQUEST, kService);
}

From source file:org.ojbc.adapters.analyticaldatastore.personid.IndexedIdentifierGenerationStrategy.java

/**
 * This method will back up the lucene cache using the specified backup path.
 * It will create a new directory with the format yyyy_MM_dd_HH_mm_ss which will
 * contain the backed up index.  Hot backups are allowed.
 * /* w w w . j  a  va 2 s . c o m*/
 */
@Override
public String backup() throws Exception {
    SnapshotDeletionPolicy snapshotter = (SnapshotDeletionPolicy) indexWriter.getConfig()
            .getIndexDeletionPolicy();

    IndexCommit commit = null;
    String backupFileDirectory = "";

    try {
        LocalDateTime today = LocalDateTime.now();
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuu_MM_dd_HH_mm_ss");
        String dateTimeStamp = today.format(dtf);

        if (!(indexBackupRoot.endsWith("/") || indexBackupRoot.endsWith("\\"))) {
            indexBackupRoot = indexBackupRoot + System.getProperty("file.separator");
        }

        backupFileDirectory = indexBackupRoot + dateTimeStamp + System.getProperty("file.separator");

        commit = snapshotter.snapshot();
        for (String fileName : commit.getFileNames()) {
            log.debug("File Name: " + fileName);

            File srcFile = new File(indexDirectoryPath + System.getProperty("file.separator") + fileName);
            File destFile = new File(backupFileDirectory + System.getProperty("file.separator") + fileName);

            FileUtils.copyFile(srcFile, destFile);

        }
    } catch (Exception e) {
        log.error("Exception", e);
    } finally {
        snapshotter.release(commit);
    }

    return backupFileDirectory;
}

From source file:de.elbe5.base.data.XmlData.java

public void addDateAttribute(Element node, String key, LocalDateTime date) {
    if (date != null) {
        addAttribute(node, key, date.format(datetimeFormatter));
    }// ww w.  j a v a  2 s  . c om
}

From source file:com.publictransitanalytics.scoregenerator.output.TimeQualifiedPointAccessibility.java

public TimeQualifiedPointAccessibility(final PathScoreCard scoreCard, final Grid grid, final Center center,
        final LocalDateTime time, final Duration tripDuration, final boolean backward,
        final Duration inServiceTime) throws InterruptedException {
    type = AccessibilityType.TIME_QUALIFIED_POINT_ACCESSIBILITY;
    direction = backward ? Direction.INBOUND : Direction.OUTBOUND;
    mapBounds = new Bounds(grid.getBounds());
    this.center = new Point(center.getLogicalCenter().getPointRepresentation());
    this.time = time.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));

    this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true);
    final ImmutableMap.Builder<Bounds, FullSectorReachInformation> builder = ImmutableMap.builder();

    final TaskIdentifier task = new TaskIdentifier(time, center);

    final Set<Sector> sectors = grid.getAllSectors();
    for (final Sector sector : sectors) {
        final MovementPath sectorPath = scoreCard.getBestPath(sector, task);
        if (sectorPath != null) {
            final Bounds sectorBounds = new Bounds(sector);

            builder.put(sectorBounds, new FullSectorReachInformation(sectorPath));
        }/*  ww  w.ja v  a 2  s.c o  m*/
    }
    sectorPaths = builder.build();
    totalSectors = grid.getReachableSectors().size();
    inServiceSeconds = inServiceTime.getSeconds();
}

From source file:lumbermill.internal.aws.AWSV4SignerImpl.java

public Map<String, String> getSignedHeaders(String uri, String method, Map<String, String> queryParams,
        Map<String, String> headers, Optional<byte[]> payload) {
    final LocalDateTime now = clock.get();
    final AWSCredentials credentials = credentialsProvider.getCredentials();
    final Map<String, String> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    result.putAll(headers);/* w w w.j  a  v  a 2 s.  c  o  m*/
    if (!result.containsKey(DATE)) {
        result.put(X_AMZ_DATE, now.format(BASIC_TIME_FORMAT));
    }
    if (AWSSessionCredentials.class.isAssignableFrom(credentials.getClass())) {
        result.put(SESSION_TOKEN, ((AWSSessionCredentials) credentials).getSessionToken());
    }

    final StringBuilder headersString = new StringBuilder();
    final ImmutableList.Builder<String> signedHeaders = ImmutableList.builder();

    for (Map.Entry<String, String> entry : result.entrySet()) {
        headersString.append(headerAsString(entry)).append(RETURN);
        signedHeaders.add(entry.getKey().toLowerCase());
    }

    final String signedHeaderKeys = JOINER.join(signedHeaders.build());
    final String canonicalRequest = method + RETURN + uri + RETURN + queryParamsString(queryParams) + RETURN
            + headersString.toString() + RETURN + signedHeaderKeys + RETURN
            + toBase16(hash(payload.orElse(EMPTY.getBytes(Charsets.UTF_8))));
    final String stringToSign = createStringToSign(canonicalRequest, now);
    final String signature = sign(stringToSign, now, credentials);
    final String autorizationHeader = AWS4_HMAC_SHA256_CREDENTIAL + credentials.getAWSAccessKeyId() + SLASH
            + getCredentialScope(now) + SIGNED_HEADERS + signedHeaderKeys + SIGNATURE + signature;

    result.put(AUTHORIZATION, autorizationHeader);
    return ImmutableMap.copyOf(result);
}

From source file:net.resheim.eclipse.timekeeper.internal.TaskActivationListener.java

@Override
public void preTaskActivated(ITask task) {
    LocalDateTime now = LocalDateTime.now();
    String startString = Activator.getValue(task, Activator.START);
    String tickString = Activator.getValue(task, Activator.TICK);
    if (startString != null) {
        LocalDateTime ticked = LocalDateTime.parse(tickString);
        LocalDateTime stopped = LocalDateTime.now();
        long seconds = ticked.until(stopped, ChronoUnit.SECONDS);
        String time = DurationFormatUtils.formatDuration(seconds * 1000, "H:mm", true);
        boolean confirm = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Add elapsed time?",
                "Work was already started and task was last updated on "
                        + ticked.format(DateTimeFormatter.ofPattern("EEE e, HH:mm", Locale.US))
                        + ". Continue and add the elapsed time since (" + time + ") to the task total?");
        if (confirm) {
            Activator.accumulateTime(task, startString, ticked.until(LocalDateTime.now(), ChronoUnit.MILLIS));
        }/*from   w  w  w .j  av  a 2  s. c  om*/
    }
    Activator.setValue(task, Activator.TICK, now.toString());
    Activator.setValue(task, Activator.START, now.toString());
}

From source file:net.tradelib.core.Series.java

public double get(LocalDateTime ts, int colId) {
    int rowId = Collections.binarySearch(index, ts);
    if (rowId < 0) {
        throw new BadIndexException(
                ts.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " is not in the index");
    }// w w w  . ja v  a 2 s. c om
    return data.get(colId).get(rowId);
}

From source file:fi.csc.emrex.smp.ThymeController.java

private String generatePersonalLogLine(HttpServletRequest httpRequest, Person person, String source)
        throws Exception {
    String personalLogLine = source + "\t" + person.getFullName();
    DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    LocalDateTime startTime = (LocalDateTime) context.getSession().getAttribute("sessionStartTime");
    if (startTime == null) {
        startTime = LocalDateTime.now();
    }//from   ww w .j  a  v  a  2s .c om
    personalLogLine += "\t" + startTime.format(dateFormatter);

    String url = httpRequest.getHeader("Referer");
    String NCPDomain = "";
    if (url != null) {
        URI uri = new URI(url);
        NCPDomain = uri.getHost();
    }

    personalLogLine += "\t" + NCPDomain;
    personalLogLine += "\t" + httpRequest.getParameter("returnCode");
    return personalLogLine;
}

From source file:com.publictransitanalytics.scoregenerator.output.PointAccessibility.java

public PointAccessibility(final int taskCount, final PathScoreCard scoreCard, final Grid grid,
        final PointLocation centerPoint, final LocalDateTime startTime, final LocalDateTime lastTime,
        final Duration samplingInterval, final Duration tripDuration, final boolean backward,
        final Duration inServiceTime) throws InterruptedException {
    type = AccessibilityType.POINT_ACCESSIBILITY;
    direction = backward ? Direction.INBOUND : Direction.OUTBOUND;
    mapBounds = new Bounds(grid.getBounds());
    center = new Point(centerPoint);
    this.startTime = startTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.endTime = lastTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));
    this.samplingInterval = DurationFormatUtils.formatDurationWords(samplingInterval.toMillis(), true, true);

    this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true);

    this.taskCount = taskCount;

    final Set<Sector> sectors = grid.getAllSectors();
    totalSectors = grid.getReachableSectors().size();

    final ImmutableMap.Builder<Bounds, SectorReachInformation> informationBuilder = ImmutableMap.builder();

    for (final Sector sector : sectors) {
        final Map<LogicalTask, MovementPath> taskPaths = scoreCard.getBestPaths(sector);
        if (!taskPaths.isEmpty()) {
            final ImmutableSet.Builder<MovementPath> bestPathsBuilder = ImmutableSet.builder();
            int count = 0;
            for (final MovementPath taskPath : taskPaths.values()) {
                if (taskPath != null) {
                    bestPathsBuilder.add(taskPath);
                    count++;//from w w w  .j a va  2  s  . co m
                }
            }
            final Bounds bounds = new Bounds(sector);
            final Set<LocalDateTime> reachTimes = scoreCard.getReachedTimes(sector);
            final SectorReachInformation information = new SectorReachInformation(bestPathsBuilder.build(),
                    count, reachTimes);
            informationBuilder.put(bounds, information);
        }
    }
    sectorPaths = informationBuilder.build();

    inServiceSeconds = inServiceTime.getSeconds();
}

From source file:no.kantega.openaksess.search.searchlog.action.ViewSearchLogAction.java

private void dateSpecifiedSearch(Map<String, Object> model, int siteId, String fromDateParam,
        String toDateParam, Integer numberOfRows) {
    LocalDateTime fromDate = getFromDate(fromDateParam).atTime(0, 0);
    LocalDateTime toDate = getToDate(toDateParam).atTime(23, 59, 59, 999);

    model.put("numSearches", searchLogDao.getSearchCountForPeriod(fromDate, toDate, siteId));
    model.put("most", searchLogDao.getMostPopularQueries(siteId, fromDate, toDate, numberOfRows));
    model.put("least", searchLogDao.getQueriesWithLeastHits(siteId, fromDate, toDate, numberOfRows));

    model.put("startDate", fromDate.format(formatter));
    model.put("endDate", toDate.format(formatter));
}