Example usage for java.util Calendar DAY_OF_WEEK

List of usage examples for java.util Calendar DAY_OF_WEEK

Introduction

In this page you can find the example usage for java.util Calendar DAY_OF_WEEK.

Prototype

int DAY_OF_WEEK

To view the source code for java.util Calendar DAY_OF_WEEK.

Click Source Link

Document

Field number for get and set indicating the day of the week.

Usage

From source file:TimeUtil.java

public static long dateFormat(short weekMins) {
    long dateMillis = System.currentTimeMillis();

    synchronized (statFmtCal) {
        statFmtCal.setTime(new Date(dateMillis));

        // get the day of the week
        int nowDay = statFmtCal.get(Calendar.DAY_OF_WEEK) - 1;
        // get day of the week of stat time
        int statDay = weekMins / 1440;

        if (nowDay > statDay) {
            dateMillis -= (nowDay - statDay) * 1440 * 60 * 1000;
        } else if (nowDay < statDay) {
            dateMillis += (statDay - nowDay) * 1440 * 60 * 1000;
        }/*from   ww w.ja  v a  2  s . c  o m*/

        // now get the hour of the day
        int nowHour = statFmtCal.get(Calendar.HOUR_OF_DAY);
        int statHour = (weekMins % 1440) / 60;

        if (nowHour > statHour) {
            dateMillis -= (nowHour - statHour) * 60 * 60 * 1000;
        } else if (nowHour < statHour) {
            dateMillis += (statHour - nowHour) * 60 * 60 * 1000;
        }

        // finally minutes
        int nowMins = statFmtCal.get(Calendar.MINUTE);
        int statMins = (weekMins % 1440) % 60;

        if (nowMins > statMins) {
            dateMillis -= (nowMins - statMins) * 60 * 1000;
        } else if (nowMins < statMins) {
            dateMillis += (statMins - nowMins) * 60 * 1000;
        }
    }

    return dateMillis;
}

From source file:Main.java

public void paintComponent(Graphics g) {
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(Color.black);/* ww w  .j a  va  2 s .  c  o  m*/
    g.drawString(month.format(date), 34, 36);
    g.setColor(Color.white);
    g.drawString(year.format(date), 235, 36);

    Calendar today = Calendar.getInstance();
    today.setTime(date);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.DATE, 1);
    cal.add(Calendar.DATE, -cal.get(Calendar.DAY_OF_WEEK) + 1);
    for (int week = 0; week < 6; week++) {
        for (int d = 0; d < 7; d++) {
            Color col = Color.black;
            g.drawString(day.format(cal.getTime()), d * 30 + 46 + 4, week * 29 + 81 + 20);
            cal.add(Calendar.DATE, +1);
        }
    }
}

From source file:com.ekom.ekomerp.global.DateTimeUtils.java

public static Date getFirstDayOfWeek(Date date, Locale locale) {
    Calendar calendar = getCalendarWithoutTime(date, locale);
    calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());
    return calendar.getTime();
}

From source file:TimeUtil.java

public static String dayStringFormat(long msecs) {
    GregorianCalendar cal = new GregorianCalendar();

    cal.setTime(new Date(msecs));

    int dow = cal.get(Calendar.DAY_OF_WEEK);

    switch (dow) {
    case Calendar.MONDAY:
        return "Monday";
    case Calendar.TUESDAY:
        return "Tuesday";
    case Calendar.WEDNESDAY:
        return "Wednesday";
    case Calendar.THURSDAY:
        return "Thursday";
    case Calendar.FRIDAY:
        return "Friday";
    case Calendar.SATURDAY:
        return "Saturday";
    case Calendar.SUNDAY:
        return "Sunday";
    }//from  www  .  j a v  a  2  s. c o  m

    return "Unknown";
}

From source file:calendar.services.transformers.EntryToDayTransformer.java

@Override
public DaySummary transform(List<Entry> entryList) {

    BigDecimal total = new BigDecimal(0);
    Calendar cal = Calendar.getInstance();
    cal.setTime(this.date);
    if (!entryList.isEmpty()) {
        daySummary.setEntries(entryList);
        total = entryList.stream().map((x) -> x.getHours()).reduce((x, y) -> x.add(y)).get();
    }/* w  w w . j a  va  2 s. c  o  m*/

    daySummary.setDay(cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.UK));

    daySummary.setTotal(total);

    return daySummary;
}

From source file:net.indialend.attendance.scheduler.AttendanceCalculation.java

public WorkingDays getWorkingDay(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from w  w w .j  a v a 2s  .com
    int day = calendar.get(Calendar.DAY_OF_WEEK);

    WorkingDays today = null;
    List<WorkingDays> workingDays = holidayService.getWorkingDays();
    for (WorkingDays days : workingDays) {

        if (days.getWorkingDay().getNumVal() == day) {

            today = days;
            break;
        }
    }
    return today;
}

From source file:com.easysoft.build.utils.PatchUtil.java

/**
 * ?/*from  w  ww.j  a v  a 2 s . com*/
 * @param date
 * @return
 */
public static String getBackupDir(Date date, boolean isWeekbug) {
    if (isWeekbug) {//BUG
        Calendar cal = Calendar.getInstance();
        String dir = new SimpleDateFormat("yyyyMMdd/").format(date);

        if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {//08
            dir += "08/";
        } else {//02-07
            dir += new DecimalFormat("00/").format(cal.get(Calendar.DAY_OF_WEEK));
        }
        return dir;
    } else {
        return new SimpleDateFormat("yyyy/MM/dd/").format(date);
    }
}

From source file:CalendarDemo.java

public void format() {

    // Tell the calendar what date/time to format
    calendar.setTime(timeNow);/*from w w  w  .  j a v a  2s  .c o  m*/

    // print out most of the known fields
    System.out.println("ERA: " + calendar.get(Calendar.ERA));
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
    System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
    System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
    System.out.println("DATE: " + calendar.get(Calendar.DATE));
    System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
    System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
    System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
    System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
    System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
    System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
    System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
    System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
    System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)));
    System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000)));
}

From source file:com.spoiledmilk.cykelsuperstier.break_rote.MetroData.java

public static ArrayList<ITransportationInfo> getNext3Arrivals(String line, String startStation,
        String endStation, Context context) {
    ArrayList<ITransportationInfo> ret = new ArrayList<ITransportationInfo>();
    String bufferString = Util.stringFromJsonAssets(context, "stations/" + filename);
    JsonNode actualObj = Util.stringToJsonNode(bufferString);
    JsonNode lines = actualObj.get("lines");
    for (int i = 0; i < lines.size(); i++) {
        JsonNode lineJson = lines.get(i);
        if (lineJson.get("name").asText().contains(line)) {
            Calendar calendar = Calendar.getInstance();
            int day = calendar.get(Calendar.DAY_OF_WEEK);
            if (day == 1)
                day = 6;//from  w  w  w .  j a v  a2 s . c  om
            else
                day -= 2;
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            int minute = calendar.get(Calendar.MINUTE);
            int period = 0, endTime = 0; // startTime
            try {
                if ((day == 4 || day == 5) && hour >= 0 && hour <= 7) { // Friday and Saturday night
                    period = lineJson.get("timetable").get("friday_saturday_night").get(0).get("period")
                            .asInt();
                    endTime = lineJson.get("timetable").get("friday_saturday_night").get(0).get("end_time")
                            .asInt();
                } else if ((day < 4 || day == 6) && hour >= 0 && hour <= 5) { // other days at night
                    JsonNode timetableNode = lineJson.get("timetable");
                    JsonNode timetableNodeContainer = timetableNode.get("sunday_thursday_night");
                    period = timetableNodeContainer.get(0).get("period").asInt();
                    endTime = timetableNodeContainer.get(0).get("end_time").asInt();
                } else {
                    JsonNode nodeRushour = lineJson.get("timetable").get("weekdays_rushour");
                    JsonNode nodeOutsideRushour = lineJson.get("timetable").get("weekdays_outside_rushour");
                    if ((day >= 0 && day < 5) && hour >= nodeRushour.get(0).get("start_time").asInt()
                            && hour < nodeRushour.get(0).get("end_time").asInt()) {
                        endTime = nodeRushour.get(0).get("end_time").asInt();
                        period = nodeRushour.get(0).get("period").asInt();
                    } else if ((day >= 0 && day < 5) && hour >= nodeRushour.get(1).get("start_time").asInt()
                            && hour < nodeRushour.get(1).get("end_time").asInt()) {
                        endTime = nodeRushour.get(1).get("end_time").asInt();
                        period = nodeRushour.get(1).get("period").asInt();
                    } else if (hour >= nodeOutsideRushour.get(0).get("start_time").asInt()
                            && hour < nodeOutsideRushour.get(0).get("end_time").asInt()) {
                        endTime = nodeOutsideRushour.get(0).get("end_time").asInt();
                        period = nodeOutsideRushour.get(0).get("period").asInt();
                    } else {
                        endTime = nodeOutsideRushour.get(1).get("end_time").asInt();
                        period = nodeOutsideRushour.get(1).get("period").asInt();
                    }

                }
                int currentHour = hour;
                int currentMinute = minute;
                int count = 0;
                period *= getTimeBetweenStations(line, startStation, endStation, context);
                while (count < 3) {
                    for (int k = 0; k < 60 && count < 3; k += period % 60) {
                        if (k >= currentMinute) {
                            currentMinute = k % 60;
                            currentHour += period / 60;
                            String arrivalTime = (currentHour < 10 ? "0" + currentHour : "" + currentHour) + ":"
                                    + (currentMinute < 10 ? "0" + currentMinute : "" + currentMinute);
                            int destHour = currentHour + period / 60;
                            int destMinute = currentMinute + period % 60;
                            if (destMinute > 59) {
                                destHour += destMinute / 60;
                                destMinute = destMinute % 60;
                            }
                            String destTime = (destHour < 10 ? "0" + destHour : "" + destHour) + ":"
                                    + (destMinute < 10 ? "0" + destMinute : "" + destMinute);
                            ret.add(new MetroData(arrivalTime, destTime, period));
                            count++;
                        }
                    }
                    currentMinute = 0;
                    if ((++currentHour) >= endTime)
                        break;
                }
            } catch (Exception e) {
                LOG.e(e.getLocalizedMessage());
            }
            break;
        }
    }
    return ret;
}

From source file:net.chrisrichardson.foodToGo.placeOrderTransactionScripts.dao.RestaurantDAOIBatisImpl.java

public List findAvailableRestaurants(Address deliveryAddress, Date deliveryTime) {
    Calendar c = Calendar.getInstance();
    c.setTime(deliveryTime);/*from  w w  w .j a  va 2  s  .  co m*/
    int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    String zipCode = deliveryAddress.getZip();

    Map deliveryInfo = new HashMap();
    deliveryInfo.put("zipCode", zipCode);
    deliveryInfo.put("dayOfWeek", new Integer(dayOfWeek));
    deliveryInfo.put("deliveryTime", hour * 100 + minute);
    return getSqlMapClientTemplate().queryForList("findAvailableRestaurants", deliveryInfo);
}