Java Day of Week dayForWeek(String pTime)

Here you can find the source of dayForWeek(String pTime)

Description

day For Week

License

Apache License

Declaration

public static int dayForWeek(String pTime) 

Method Source Code


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

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

public class Main {

    public static int dayForWeek(String pTime) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        try {/*from ww w . jav a  2 s. com*/
            c.setTime(format.parse(pTime));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int dayForWeek = 0;
        if (c.get(Calendar.DAY_OF_WEEK) == 1) {
            dayForWeek = 7;
        } else {
            dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
        }
        return dayForWeek;
    }

    public static int dayForWeek(Date pTime) {
        Calendar c = Calendar.getInstance();
        c.setTime(pTime);
        int dayForWeek = 0;
        if (c.get(Calendar.DAY_OF_WEEK) == 1) {
            dayForWeek = 7;
        } else {
            dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
        }
        return dayForWeek;
    }
}

Related

  1. calculateBusinessDays(Date startDate, Date endDate, int firstWeekendDay, int secondWeekendDay)
  2. Day_Of_Week(String Date, int DayCase)
  3. dayForWeek(String pTime)
  4. dayForWeek(String weeks)
  5. dayNumberOfWeek(Date date)
  6. DayOfTheWeek(Date dt)
  7. dayOfWeek(Date date)