JAVA gets the specified date is the day of the week

Recently, the company has a requirement change. Before, the user can only withdraw the cash amount to the account once a month, but now it is changed to once a week.
Check whether it is Monday, here is a simple example, you can check whether you have withdrawn according to your own needs and field conditions, such as querying the withdrawal time of the database.

insert image description here
Outputs the date for the specified date. (Day of the week)

/**
 * 获取指定日期是星期几<br>
 *
 * @param date
 * @return 指定日期是星期几
 */
public static String getWeekOfDate(Date date) {
    
    
    String[] weekDays = {
    
     "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
    if (w < 0)
        w = 0;
    return weekDays[w];
}

Guess you like

Origin blog.csdn.net/weixin_43860634/article/details/130989051