Here you can find the source of getDayOfWeek(String date, String pattern)
public static int getDayOfWeek(String date, String pattern) throws Exception
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static int getDayOfWeek(String date, String pattern) throws Exception { Calendar c = Calendar.getInstance(); int result = -1; SimpleDateFormat sdf = new SimpleDateFormat(pattern); Date d = sdf.parse(date); c.setTime(d);//from w ww . jav a 2 s .c om result = c.get(Calendar.DAY_OF_WEEK) - 1; return result; } }