get Day Of Week from string in format dd/MM/yyyy HH:mm - Java java.time

Java examples for java.time:Week

Description

get Day Of Week from string in format dd/MM/yyyy HH:mm

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 DATE_TIME_FORMATTER = DateTimeFormatter
            .ofPattern("dd/MM/yyyy HH:mm");
    private static final String TIME_PADDING = " 00:00";

    public static String getDayOfWeek(String inputDate) {
        try {//from   www . j ava2  s.c  om
            LocalDateTime date = parseStringToDateTime(inputDate
                    + TIME_PADDING);
            if (date != null) {
                return date.getDayOfWeek().toString();
            }
        } catch (DateTimeException e) {
        }
        return inputDate;
    }

    /*** Methods ***/
    // parses string exclusively in this format "dd/mm/yyyy HH:mm"
    public static LocalDateTime parseStringToDateTime(String inputString) {
        try {
            return LocalDateTime.parse(inputString, DATE_TIME_FORMATTER);
        } catch (DateTimeException e) {
            return null;
        }
    }
}

Related Tutorials