Here you can find the source of getWeekDay(String dateString, int weekDay)
Parameter | Description |
---|---|
dateString | String value of date |
weekDay | int index of weekday to get, first Calendar.SUNDAY, last Calendar.SATURDAY |
public static Date getWeekDay(String dateString, int weekDay)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { /**/*from w w w . j ava2 s . co m*/ * return date's weekday value of specified string value in format: yyyy-MM-dd * Date first = DateUtil.getMonday(today,Calendar.SUNDAY); * Date last = DateUtil.getMonday(today,Calendar.SATURDAY); * * @param dateString String value of date * @param weekDay int index of weekday to get, first Calendar.SUNDAY, last Calendar.SATURDAY * @return Date value */ public static Date getWeekDay(String dateString, int weekDay) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = simpleDateFormat.parse(dateString); } catch (Exception e) { e.printStackTrace(); } Calendar calendar = Calendar.getInstance(); if (date != null) { calendar.setTime(date); } // DAY_OF_WEEK // Field number for get and set indicating the day of the week. This field takes values // SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, and SATURDAY calendar.set(Calendar.DAY_OF_WEEK, weekDay); calendar.add(Calendar.DATE, 1); return calendar.getTime(); } }