Example usage for java.time.format DateTimeFormatter ISO_LOCAL_DATE_TIME

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

Introduction

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

Prototype

DateTimeFormatter ISO_LOCAL_DATE_TIME

To view the source code for java.time.format DateTimeFormatter ISO_LOCAL_DATE_TIME.

Click Source Link

Document

The ISO date-time formatter that formats or parses a date-time without an offset, such as '2011-12-03T10:15:30'.

Usage

From source file:com.example.AuthzApp.java

@Bean
ObjectMapper objectMapper() {/*from  w w w .jav  a  2s.c o  m*/
    final JavaTimeModule javaTimeModule = new JavaTimeModule();
    javaTimeModule.addSerializer(LocalDateTime.class,
            new LocalDateTimeSerializer(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
    return new Jackson2ObjectMapperBuilder()
            .featuresToDisable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).modules(javaTimeModule)
            .serializationInclusion(JsonInclude.Include.NON_NULL)
            .propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE).build();
}

From source file:com.bekwam.resignator.model.ConfigurationJSONAdapter.java

@Override
public Configuration deserialize(JsonElement jsonElement, Type type,
        JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {

    if (logger.isDebugEnabled()) {
        logger.debug("[DESERIALIZE]");
    }/* w w w  .jav a  2s . c  om*/

    JsonObject obj = (JsonObject) jsonElement;

    JsonElement apElement = obj.get("activeProfile");
    String ap = "";
    if (apElement != null) {
        ap = apElement.getAsString();
    }

    JsonElement jdkElem = obj.get("jdkHome");
    String jdkHome = "";
    if (jdkElem != null) {
        jdkHome = jdkElem.getAsString();
    }

    JsonElement hpElem = obj.get("hashedPassword");
    String hp = "";
    if (hpElem != null) {
        hp = hpElem.getAsString();
    }

    JsonElement ludElem = obj.get("lastUpdatedDate");
    String lud = "";
    LocalDateTime lastUpdatedDate = null;
    if (ludElem != null) {
        lud = ludElem.getAsString();
        if (StringUtils.isNotEmpty(lud)) {
            lastUpdatedDate = LocalDateTime.parse(lud, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        }
    }

    JsonArray recentProfiles = obj.getAsJsonArray("recentProfiles");
    JsonArray profiles = obj.getAsJsonArray("profiles");

    if (logger.isDebugEnabled()) {
        logger.debug("[DESERIALIZE] rp={}, ap={}, jdkHome={}, keytool={}, profiles={}",
                recentProfiles.toString(), ap, jdkHome, profiles.toString());
    }

    Configuration conf = new Configuration();
    conf.setActiveProfile(Optional.of(ap));
    conf.setJDKHome(Optional.of(jdkHome));
    conf.getRecentProfiles().addAll(deserializeRecentProfiles(recentProfiles));
    conf.getProfiles().addAll(deserializeProfiles(profiles));
    conf.setHashedPassword(Optional.of(hp));
    conf.setLastUpdatedDateTime(Optional.ofNullable(lastUpdatedDate));
    return conf;
}

From source file:Jimbo.Cheerlights.MQTTListener.java

/**
 * Receive an MQTT message.//  w  ww .ja v  a 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:de.steilerdev.myVerein.server.controller.user.EventController.java

/**
 * This function gathers all events for the currently logged in user. If lastChanged is stated only events that
 * changed after that moment are returned.
 *
 * @param lastChanged The date of the last changed action, correctly formatted (YYYY-MM-DDTHH:mm:ss)
 * @param currentUser The currently logged in user
 * @return A list of all events for the user that changed since the last changed moment in time (only containing
 * id's)// www  . j ava2 s  .c  o m
 */
@RequestMapping(produces = "application/json", method = RequestMethod.GET)
public ResponseEntity<List<Event>> getAllEventsForUser(@RequestParam(required = false) String lastChanged,
        @CurrentUser User currentUser) {
    List<Event> events;
    if (lastChanged != null && !lastChanged.isEmpty()) {
        logger.debug("[{}] Gathering all user events changed after {}", currentUser, lastChanged);
        LocalDateTime lastChangedTime;
        try {
            lastChangedTime = LocalDateTime.parse(lastChanged, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        } catch (DateTimeParseException e) {
            logger.warn("[{}] Unable to get all events for user, because the last changed format is wrong: {}",
                    currentUser, e.getLocalizedMessage());
            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        }
        events = eventRepository.findAllByPrefixedInvitedUserAndLastChangedAfter(
                Event.prefixedUserIDForUser(currentUser), lastChangedTime);
    } else {
        logger.debug("[{}] Gathering all user events", currentUser);
        events = eventRepository.findAllByPrefixedInvitedUser(Event.prefixedUserIDForUser(currentUser));
    }

    if (events == null || events.isEmpty()) {
        logger.warn("[{}] No events to return", currentUser);
        return new ResponseEntity<>(HttpStatus.OK);
    } else {
        logger.info("[{}] Returning {} events", currentUser, events.size());
        events.replaceAll(Event::getSendingObjectOnlyId);
        return new ResponseEntity<>(events, HttpStatus.OK);
    }
}

From source file:com.example.ResourceConfig.java

@Bean
Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
    return new Jackson2ObjectMapperBuilder().propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
            .featuresToDisable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
            .modules(new JavaTimeModule().addSerializer(LocalDateTime.class,
                    new LocalDateTimeSerializer(DateTimeFormatter.ISO_LOCAL_DATE_TIME)));
}

From source file:com.mgmtp.perfload.core.console.meta.LtMetaInfoHandler.java

/**
 * Dumps the specified meta information to specified writer.
 * /*from w ww .ja v  a2 s .com*/
 * @param metaInfo
 *            the meta information object
 * @param writer
 *            the writer
 */
public void dumpMetaInfo(final LtMetaInfo metaInfo, final Writer writer) {
    PrintWriter pr = new PrintWriter(writer);

    URL url = getClass().getProtectionDomain().getCodeSource().getLocation();
    if (url.getPath().endsWith(".jar")) {
        try {
            JarFile jarFile = new JarFile(toFile(url));
            Manifest mf = jarFile.getManifest();
            Attributes attr = mf.getMainAttributes();
            pr.printf("perfload.implementation.version=%s", attr.getValue("Implementation-Version"));
            pr.println();
            pr.printf("perfload.implementation.date=%s", attr.getValue("Implementation-Date"));
            pr.println();
            pr.printf("perfload.implementation.revision=%s", attr.getValue("Implementation-Revision"));
            pr.println();
        } catch (IOException ex) {
            log.error(ex.getMessage(), ex);
        }
    }

    pr.printf("test.file=%s", metaInfo.getTestplanFileName());
    pr.println();

    pr.printf("test.start=%s", DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(metaInfo.getStartTimestamp()));
    pr.println();
    pr.printf("test.finish=%s", DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(metaInfo.getFinishTimestamp()));
    pr.println();

    List<Daemon> daemonList = metaInfo.getDaemons();
    Collections.sort(daemonList);

    for (Daemon daemon : daemonList) {
        pr.printf("daemon.%d=%s:%d", daemon.getId(), daemon.getHost(), daemon.getPort());
        pr.println();
    }

    List<String> lpTargets = metaInfo.getLpTargets();
    if (!lpTargets.isEmpty()) {
        Collections.sort(lpTargets);
        pr.printf("targets=%s", on(',').join(lpTargets));
        pr.println();
    }

    List<String> lpOperations = metaInfo.getLpOperations();
    if (!lpOperations.isEmpty()) {
        Collections.sort(lpOperations);
        pr.printf("operations=%s", on(',').join(lpOperations));
        pr.println();
    }

    List<Executions> executionsList = metaInfo.getExecutionsList();
    Collections.sort(executionsList);
    for (Executions executions : executionsList) {
        pr.printf("executions.%s.%s=%d", executions.operation, executions.target, executions.executions);
        pr.println();
    }
}

From source file:com.offbynull.peernetic.debug.visualizer.JGraphXVisualizer.java

@Override
public void step(String output, Command<A>... commands) {
    Validate.notNull(output);/* w w  w .  j ava 2s  .co m*/
    Validate.noNullElements(commands);

    String name = Thread.currentThread().getName();
    String dateStr = ZonedDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);

    textOutputArea.append(dateStr + " / " + name + " - " + output + " \n");
    textOutputArea.setCaretPosition(textOutputArea.getDocument().getLength());

    Recorder<A> rec = this.recorder.get();
    if (rec != null) {
        rec.recordStep(output, commands);
    }

    queueCommands(Arrays.asList(commands));
}

From source file:com.fns.grivet.controller.PersistDocumentationTest.java

@Test
// GET (bounded by createdTimeStart and createdTimeEnd)
public void fetchByTimeRange() {
    try {//from   w  ww. ja  va  2s  .  com
        defineType("TestType2");
        createType("TestType2", "TestTypeData2");
        String createdTimeStart = LocalDateTime.now().minusMinutes(15)
                .format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        String createdTimeEnd = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        mockMvc.perform(get("/api/v1/type/TestType2").param("createdTimeStart", createdTimeStart)
                .param("createdTimeEnd", createdTimeEnd).contentType(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk()).andExpect(content().json(asArray(payload("TestTypeData2"))));
    } catch (Exception e) {
        fail(e.getMessage());
    }
}

From source file:com.omertron.slackbot.functions.scheduler.AbstractBotTask.java

/**
 * Return the current date/time formatted for printing
 *
 * @return/*from w  w  w  .  j a va2  s . co  m*/
 */
protected static final String formattedDateTime() {
    return localeDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
}

From source file:com.bekwam.resignator.model.ConfigurationJSONAdapter.java

@Override
public JsonElement serialize(Configuration configuration, Type type,
        JsonSerializationContext jsonSerializationContext) {

    if (logger.isDebugEnabled()) {
        logger.debug("[SERIALIZE]");
    }//  w  w  w  .  java  2  s .  com

    String ap = configuration.getActiveProfile().orElse("");
    String jdkHome = configuration.getJDKHome().orElse("");
    JsonArray profiles = serializeProfiles(configuration.getProfiles());
    String hp = configuration.getHashedPassword().orElse("");
    String lud = "";
    if (configuration.getLastUpdatedDateTime().isPresent()) {

        lud = configuration.getLastUpdatedDateTime().get().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
    }

    JsonObject root = new JsonObject();
    root.addProperty("activeProfile", ap);
    root.addProperty("jdkHome", jdkHome);
    root.addProperty("hashedPassword", hp);
    root.addProperty("lastUpdatedDate", lud);

    if (logger.isDebugEnabled()) {
        logger.debug("[SERIALIZE] ap={}, jdkHome={}, hp empty?={}, lastUpdatedDate={}", ap, jdkHome,
                StringUtils.isEmpty(hp), lud);
    }

    root.add("recentProfiles", serializeRecentProfiles(configuration.getRecentProfiles()));
    root.add("profiles", profiles);

    return root;
}