Example usage for java.time LocalDateTime parse

List of usage examples for java.time LocalDateTime parse

Introduction

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

Prototype

public static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter) 

Source Link

Document

Obtains an instance of LocalDateTime from a text string using a specific formatter.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.parse("2014-06-30T12:01:00", DateTimeFormatter.ISO_DATE_TIME);

    System.out.println(a);//from w ww.ja  v  a  2 s  . co  m
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.now();
    // default format
    System.out.println("Default format of LocalDate=" + date);
    // specific format
    System.out.println(date.format(DateTimeFormatter.ofPattern("d::MMM::uuuu")));
    System.out.println(date.format(DateTimeFormatter.BASIC_ISO_DATE));

    LocalDateTime dateTime = LocalDateTime.now();
    // default format
    System.out.println("Default format of LocalDateTime=" + dateTime);
    // specific format
    System.out.println(dateTime.format(DateTimeFormatter.ofPattern("d::MMM::uuuu HH::mm::ss")));
    System.out.println(dateTime.format(DateTimeFormatter.BASIC_ISO_DATE));

    Instant timestamp = Instant.now();
    // default format
    System.out.println("Default format of Instant=" + timestamp);

    // Parse examples
    LocalDateTime dt = LocalDateTime.parse("27::Apr::2014 21::39::48",
            DateTimeFormatter.ofPattern("d::MMM::uuuu HH::mm::ss"));
    System.out.println("Default format after parsing = " + dt);
}

From source file:Main.java

public static LocalDateTime getLocalDateTimeFromDB(ResultSet rs, String column) throws SQLException {
    String date = rs.getString(column);
    if (date != null) {
        return LocalDateTime.parse(date, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
    } else {/*from www  .  j a  v  a  2s. com*/
        return null;
    }
}

From source file:Main.java

private static String getDateAsStringIncrementedByYear(String inputDateStr, String pattern,
        long yearsToIncrement) {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
    LocalDateTime dateTime = LocalDateTime.parse(inputDateStr, formatter);
    return dateTime.plusYears(yearsToIncrement).format(formatter);
}

From source file:Main.java

private static long getMillis(String strDate, DateTimeFormatter formatter, ZoneId zone) {
    LocalDateTime localDateTime = LocalDateTime.parse(strDate, formatter);
    ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, zone);
    Instant instant = zonedDateTime.toInstant();
    long milli = instant.toEpochMilli();
    return milli;
}

From source file:Main.java

public static LocalDateTime parse(String text) {
    LocalDateTime dt = null;// w  w w .ja  va  2s. co m
    if (text != null && text.length() == PATTERN.length()) {
        dt = LocalDateTime.parse(text, FMT);
    }
    return dt;
}

From source file:com.devcraftsman.blog.post.api.util.ISOLocalDateTimeDeserializer.java

@Override
public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    if (p.getText() != null)
        return LocalDateTime.parse(p.getText(), DateTimeFormatter.ISO_DATE_TIME);
    else//from  w  w  w  .  j a v  a2s  .c om
        return null;
}

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

@Override
public LocalDateTime parse(String text, Locale locale) throws ParseException {
    return LocalDateTime.parse(text, getCurrentDateTimeFormatter());
}

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

public LocalDateTime parse(final String text, Locale locale) throws ParseException {
    return LocalDateTime.parse(text, createDateFormat());
}

From source file:com.btmatthews.atlas.core.domain.jsr310.LocalDateTimeDeserializer.java

@Override
public LocalDateTime deserialize(final JsonParser parser, final DeserializationContext context)
        throws IOException {
    final ObjectCodec codec = parser.getCodec();
    final JsonNode node = codec.readTree(parser);
    return LocalDateTime.parse(node.asText(), DATE_TIME_FORMATTER);
}