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:ch.rasc.edsutil.jackson.ISO8601LocalDateTimeSerializer.java

@Override
public void serialize(LocalDateTime value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    jgen.writeString(value.format(DF_PATTERN));
}

From source file:se.nrm.dina.logic.util.HelpClass.java

public String dateTimeToString(LocalDateTime date) {
    return date == null ? null : date.format(FORMATTER);
}

From source file:ch.rasc.wampspring.demo.various.scheduler.LocalDateTimeSerializer.java

@Override
public void serialize(LocalDateTime value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {

    jgen.writeString(value.format(DT_PATTERN));
}

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

@Override
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers)
        throws IOException {
    if (value != null) {
        gen.writeString(value.format(DateTimeFormatter.ISO_DATE_TIME));
    }/* ww w . jav  a  2 s  .  com*/

}

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

@Override
public void serialize(final LocalDateTime value, final JsonGenerator generator,
        final SerializerProvider provider) throws IOException {
    generator.writeString(value.format(DATE_TIME_FORMATTER));
}

From source file:org.graylog.plugins.backup.strategy.FsBackupStrategy.java

@Override
protected void pack() throws Exception {
    LocalDateTime now = LocalDateTime.now();
    String dateFormat = now.format(formatter);
    String srcFolder = backupStruct.getTargetPath() + File.separator + GRAYLOG_SCHEMA_NAME;
    String dstFolder = backupStruct.getTargetPath() + File.separator + GRAYLOG_SCHEMA_NAME + dateFormat
            + ".zip";
    ZipUtil.pack(new File(srcFolder), new File(dstFolder));
    LOG.info("Graylog config backup completed");
    FileUtils.deleteDirectory(new File(srcFolder));
}

From source file:fi.helsinki.opintoni.service.CalendarService.java

private DateTime calDateTimeAsUtc(LocalDateTime localDateTime) {
    String utc = localDateTime.format(DateTimeFormatter.ofPattern(DateFormatter.UTC_TIME_FORMAT));
    try {/*w  ww  .  jav a 2 s  .c om*/
        return new DateTime(utc, DateFormatter.UTC_TIME_FORMAT, true);
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}

From source file:Jimbo.Cheerlights.MQTTListener.java

/**
 * Receive an MQTT message./*ww w . j  a va 2 s. co  m*/
 * 
 * @param topic The topic it's on
 * @param message The message itself
 */
@Override
public void receive(String topic, String message) {
    try {
        JSONObject j = new JSONObject(message);

        final Instant instant = Instant.ofEpochMilli(j.getLong("sent")).truncatedTo(ChronoUnit.SECONDS);
        final LocalDateTime stamp = LocalDateTime.ofInstant(instant, ZONE);
        final String when = stamp.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);

        LOG.log(Level.INFO, "{0} (@{1}) sent {2}: {3}",
                new Object[] { j.getString("name"), j.getString("screen"), when, j.getString("text") });
        target.update(j.getInt("colour"));
    }

    catch (JSONException | IOException e) {
        LOG.log(Level.WARNING, "Unable to parse: \"{0}\": {1}",
                new Object[] { message, e.getLocalizedMessage() });
    }
}

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

/**
 * Simply selects the home view to render by returning its name.
 *///  w w w . 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:com.btmatthews.atlas.core.dao.mongo.MongoLocalDateTimeSerializer.java

@Override
public void serialize(final LocalDateTime value, final JsonGenerator generator,
        final SerializerProvider provider) throws IOException {
    generator.writeStartObject();//from   w  w w.  ja  v  a  2 s.  c  o m
    generator.writeStringField("$date", value.format(DATE_TIME_FORMATTER));
    generator.writeEndObject();
}