Here you can find the source of getDAYOFWEEK(String strDate)
Parameter | Description |
---|---|
strDate | Fecha |
public static String getDAYOFWEEK(String strDate)
//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; } }