get Time String from LocalDateTime - Java java.time

Java examples for java.time:LocalDateTime

Description

get Time String from LocalDateTime

Demo Code


//package com.java2s;
import java.time.DateTimeException;
import java.time.LocalDateTime;

import java.time.format.DateTimeFormatter;

public class Main {
    private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter
            .ofPattern("HH:mm");

    public static String getTime(LocalDateTime inputDateTime) {
        try {/*from   w  w w  .  j a va 2 s  .  c  o m*/
            return inputDateTime.toLocalTime().format(TIME_FORMATTER);
        } catch (DateTimeException e) {
            return null;
        }
    }
}

Related Tutorials