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:org.cloud.mblog.utils.FileUtil.java

/**
 * @param date localtime/* w  ww.j  a v a2s  . c om*/
 * @return
 */
private static String getImageRelativePathByDate(LocalDateTime date) {
    // ????
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(FILE_DATE_DIR_FMT);
    String datePath = IMAGE + date.format(formatter);
    return getImageRelativePath(datePath);
}

From source file:org.cloud.mblog.utils.FileUtil.java

/**
 * @param date localtime/*from  w  w  w  . j av a2 s .  c  o m*/
 * @return
 */
private static String getThumbRelativePathByDate(LocalDateTime date) {
    // ????
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(FILE_DATE_DIR_FMT);
    String datePath = THUMBNAIL + date.format(formatter);
    return getImageRelativePath(datePath);
}

From source file:com.ndemyanovskyi.backend.DataManager.java

public static void writeLastUpdate(Bank<?> bank, Currency currency, LocalDateTime dateTime) {
    String table = getTableName(bank, currency);
    String lastUpdate = dateTime.format(of("yyyy-MM-dd hh:mm:ss.nnnnnnnnn"));
    try {/*w w  w.  j a  v a2s  .  c o  m*/
        try {
            getDatabase().queryUpdate(String
                    .format("INSERT INTO LAST_UPDATES (TABLE, LAST_UPDATE) VALUES(%s, %s)", table, lastUpdate));
        } catch (RuntimeSQLException ignored) {
        }
    } catch (RuntimeSQLException ex) {
        try {
            getDatabase().queryUpdate(String.format(
                    "UPDATE LAST_UPDATES SET LAST_UPDATE=TIMESTAMP(%s) WHERE TABLE='%s'", lastUpdate, table));
        } catch (RuntimeSQLException ignored) {
        }
    }
}

From source file:org.apache.nifi.processors.solr.SolrUtils.java

private static void writeValue(final SolrInputDocument inputDocument, final Object value,
        final String fieldName, final DataType dataType, final List<String> fieldsToIndex) throws IOException {
    final DataType chosenDataType = dataType.getFieldType() == RecordFieldType.CHOICE
            ? DataTypeUtils.chooseDataType(value, (ChoiceDataType) dataType)
            : dataType;//from  w  w  w .  j  a va2 s . co  m
    final Object coercedValue = DataTypeUtils.convertType(value, chosenDataType, fieldName);
    if (coercedValue == null) {
        return;
    }

    switch (chosenDataType.getFieldType()) {
    case DATE: {
        final String stringValue = DataTypeUtils.toString(coercedValue,
                () -> DataTypeUtils.getDateFormat(RecordFieldType.DATE.getDefaultFormat()));
        if (DataTypeUtils.isLongTypeCompatible(stringValue)) {
            LocalDate localDate = getLocalDateFromEpochTime(fieldName, coercedValue);
            addFieldToSolrDocument(inputDocument, fieldName,
                    localDate.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + 'Z', fieldsToIndex);
        } else {
            addFieldToSolrDocument(inputDocument, fieldName,
                    LocalDate.parse(stringValue).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + 'Z',
                    fieldsToIndex);
        }
        break;
    }
    case TIMESTAMP: {
        final String stringValue = DataTypeUtils.toString(coercedValue,
                () -> DataTypeUtils.getDateFormat(RecordFieldType.TIMESTAMP.getDefaultFormat()));
        if (DataTypeUtils.isLongTypeCompatible(stringValue)) {
            LocalDateTime localDateTime = getLocalDateTimeFromEpochTime(fieldName, coercedValue);
            addFieldToSolrDocument(inputDocument, fieldName,
                    localDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + 'Z', fieldsToIndex);
        } else {
            addFieldToSolrDocument(inputDocument, fieldName,
                    LocalDateTime.parse(stringValue).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + 'Z',
                    fieldsToIndex);
        }
        break;
    }
    case DOUBLE:
        addFieldToSolrDocument(inputDocument, fieldName, DataTypeUtils.toDouble(coercedValue, fieldName),
                fieldsToIndex);
        break;
    case FLOAT:
        addFieldToSolrDocument(inputDocument, fieldName, DataTypeUtils.toFloat(coercedValue, fieldName),
                fieldsToIndex);
        break;
    case LONG:
        addFieldToSolrDocument(inputDocument, fieldName, DataTypeUtils.toLong(coercedValue, fieldName),
                fieldsToIndex);
        break;
    case INT:
    case BYTE:
    case SHORT:
        addFieldToSolrDocument(inputDocument, fieldName, DataTypeUtils.toInteger(coercedValue, fieldName),
                fieldsToIndex);
        break;
    case CHAR:
    case STRING:
        addFieldToSolrDocument(inputDocument, fieldName, coercedValue.toString(), fieldsToIndex);
        break;
    case BIGINT:
        if (coercedValue instanceof Long) {
            addFieldToSolrDocument(inputDocument, fieldName, (Long) coercedValue, fieldsToIndex);
        } else {
            addFieldToSolrDocument(inputDocument, fieldName, (BigInteger) coercedValue, fieldsToIndex);
        }
        break;
    case BOOLEAN:
        final String stringValue = coercedValue.toString();
        if ("true".equalsIgnoreCase(stringValue)) {
            addFieldToSolrDocument(inputDocument, fieldName, true, fieldsToIndex);
        } else if ("false".equalsIgnoreCase(stringValue)) {
            addFieldToSolrDocument(inputDocument, fieldName, false, fieldsToIndex);
        } else {
            addFieldToSolrDocument(inputDocument, fieldName, stringValue, fieldsToIndex);
        }
        break;
    case RECORD: {
        final Record record = (Record) coercedValue;
        writeRecord(record, inputDocument, fieldsToIndex, fieldName);
        break;
    }
    case ARRAY:
    default:
        if (coercedValue instanceof Object[]) {
            final Object[] values = (Object[]) coercedValue;
            for (Object element : values) {
                if (element instanceof Record) {
                    writeRecord((Record) element, inputDocument, fieldsToIndex, fieldName);
                } else {
                    addFieldToSolrDocument(inputDocument, fieldName, coercedValue.toString(), fieldsToIndex);
                }
            }
        } else {
            addFieldToSolrDocument(inputDocument, fieldName, coercedValue.toString(), fieldsToIndex);
        }
        break;
    }
}

From source file:dhbw.clippinggorilla.external.twitter.TwitterUtils.java

/**
 * @param includedTagsSet//ww  w.j  av a 2  s  .  c o m
 * @param date
 * @return
 */
private static Query queryBuilder(Set<String> includedTagsSet, LocalDateTime date) {
    List<String> includedTags = new ArrayList<>();

    includedTags.addAll(includedTagsSet);

    String query = "";

    if (includedTags.size() > 0) {
        query = replaceWhitespaces(includedTags.get(0));
        for (int i = 1; i < includedTags.size(); i++) {
            query += " OR " + replaceWhitespaces(includedTags.get(i));
        }
    }

    //System.out.println(date.toString());
    //System.out.println(query);
    Query result = new Query(query);
    result.setResultType(Query.ResultType.popular);
    result.setSince(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
    return result;

}

From source file:org.jbb.frontend.impl.format.LocalDateTimeFormatter.java

@Override
public String print(LocalDateTime object, Locale locale) {
    return object.format(getCurrentDateTimeFormatter());
}

From source file:br.gov.sp.policiamilitar.bopmtc.conversion.DateFormatter.java

public String print(final LocalDateTime object, final Locale locale) {
    return object.format(createDateFormat());
}

From source file:se.omegapoint.facepalm.client.adapters.DocumentAdapter.java

private String date(final LocalDateTime uploadedDate) {
    return uploadedDate != null ? uploadedDate.format(DateTimeFormatter.BASIC_ISO_DATE) : "";
}

From source file:com.doctor.ignite.example.spring.IgniteDao.java

public String getTimesplice(LocalDateTime time) {
    return time.format(timeFormatter);
}

From source file:com.bekwam.mavenpomupdater.ErrorLogDelegate.java

public void log(String fileName, String message) {

    if (log.isDebugEnabled()) {
        log.debug("[LOG] fileName=" + fileName + ", message=" + message);
    }//from w  w w  .  j  a v  a  2s . co m

    LocalDateTime now = LocalDateTime.now();
    String logTime = now.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);

    tblErrors.getItems().add(new ErrorLogEntry(logTime, fileName, message));
}