Java Day of Week getDayOfWeek(String datetime)

Here you can find the source of getDayOfWeek(String datetime)

Description

get Day Of Week

License

Open Source License

Declaration

public static int getDayOfWeek(String datetime) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

public class Main {
    private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

    public static int getDayOfWeek(String datetime) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(parseDate(datetime));

        return cal.get(Calendar.DAY_OF_WEEK) - 1;
    }/*w  ww .j a  v  a2s.  c  om*/

    public static Date parseDate(String datetime) {
        try {
            return DATE_FORMAT.parse(datetime);
        } catch (ParseException e) {
            return new Date();
        }
    }

    public static Date parse(String datetime) {
        try {
            return FORMAT.parse(datetime);
        } catch (ParseException e) {
            return new Date();
        }
    }
}

Related

  1. getDayOfWeek(Date date)
  2. getDayOfWeek(int _year, int _month, int _day)
  3. getDayOfWeek(int year, int month, int day)
  4. getDayOfWeek(int year, int month, int day)
  5. getDayOfWeek(String date, String pattern)
  6. getDayOfWeek(String f)
  7. getDayOfWeek(String format, int calendarField)
  8. getDayOfWeekAsString(String sYear, String sMonth, String sDay)
  9. getDayofWeekByDay(String year, String month, String day)