Java Day getDAYOFWEEK(String strDate)

Here you can find the source of getDAYOFWEEK(String strDate)

Description

Regresa el dia de la semana, dada la fecha DOMINGO, LUNES, MARTES, MIERCOLES, JUEVES, VIERNES, SABADO

License

Apache License

Parameter

Parameter Description
strDate Fecha

Return

String Dia de la semana

Declaration

public static String getDAYOFWEEK(String strDate) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    /** Constante que define el patron estandar de presentacion de fechas */
    private static final String PATRON_FECHA_DEFAULT = "dd/MM/yyyy";

    /**//from   w  ww  . ja va 2  s  .  c o  m
     * Regresa el dia de la semana, dada la fecha  DOMINGO, LUNES, MARTES, MIERCOLES, JUEVES, VIERNES, SABADO
     *
     * @param strDate Fecha
     *
     * @return String Dia de la semana
     */
    public static String getDAYOFWEEK(String strDate) {
        String dia = null;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(convertStringToDate(strDate));

        switch (calendar.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.SUNDAY:
            dia = "DOMINGO";

            break;

        case Calendar.MONDAY:
            dia = "LUNES";

            break;

        case Calendar.TUESDAY:
            dia = "MARTES";

            break;

        case Calendar.WEDNESDAY:
            dia = "MIERCOLES";

            break;

        case Calendar.THURSDAY:
            dia = "JUEVES";

            break;

        case Calendar.FRIDAY:
            dia = "VIERNES";

            break;

        case Calendar.SATURDAY:
            dia = "SABADO";

            break;
        }

        return dia;
    }

    /**
     * Convertidor de cadenas con el patron 'dd/MM/yyyy' a fechas
     *
     * @param stringDate La cadena a transformar
     *
     * @return La fecha transformada
     */
    public static java.util.Date convertStringToDate(String stringDate) {
        return convertStringToDate(stringDate, PATRON_FECHA_DEFAULT);
    }

    public static java.util.Date convertStringToDate(String stringDate,
            String pattern) {
        java.util.Date date = null;

        try {
            SimpleDateFormat formatter = new SimpleDateFormat(pattern);
            formatter.setLenient(true);
            date = formatter.parse(stringDate);
        } catch (Exception e) {
            date = new java.util.Date();
        }

        return date;
    }
}

Related

  1. getDayNames(Locale locale)
  2. getDayNumber()
  3. getDayOfDate(Date date)
  4. getDayOffset(String date, int offset, String format)
  5. getDayofTheDate(Date d1)
  6. getDayRange(String bday, String eday)
  7. getDays(Date day, int preDays, String format)
  8. getDays(Date sd, Date ed)
  9. getDays(String yyyy)