Java Code Examples for java.util.Date#getDay()

The following examples show how to use java.util.Date#getDay() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Nullable
public String[] getRandomEasterEgg() {
    try {
        Date currentDate = new Date(System.currentTimeMillis());
        if (easterDay()) {
            return this.getEasterRabbit().split("\n");
        }
        if (currentDate.getMonth() == Calendar.DECEMBER
                && currentDate.getDay() > 20
                && currentDate.getDay() < 26) {
            return this.getXMas().split("\n");
        }
        if (chineseSpringDay()) {
            return this.getChineseNewYear().split("\n");
        }
    } catch (Exception ignored) {
    }
    return null;
}
 
Example 2
public void downloadLatestIfNewerThanDate(Date oldestDate, List<Downloader> downloaders) {
    oldestDate = clearTimeInDate(oldestDate);

    if (downloaders == null) {
        downloaders = new ArrayList<Downloader>();
    }

    if (downloaders.size() == 0) {
        downloaders.addAll(this.downloaders);
    }

    HashMap<Downloader, Date> puzzlesToDownload = new HashMap<Downloader, Date>();
    for (Downloader d : downloaders) {
        Date goodThrough = clearTimeInDate(d.getGoodThrough());
        int goodThroughDayOfWeek = goodThrough.getDay();
        if ((Arrays.binarySearch(d.getDownloadDates(), goodThroughDayOfWeek) >= 0) &&
                goodThrough.getTime() >= oldestDate.getTime()) {
            LOG.info("Will try to download puzzle " + d + " @ " + goodThrough);
            puzzlesToDownload.put(d, goodThrough);
        }
    }

    if (!puzzlesToDownload.isEmpty()) {
        download(puzzlesToDownload);
    }
}
 
Example 3
private boolean chineseSpringDay() {
    Date chineseCalender = new LunarCalendar(new Date()).getDate();
    if (chineseCalender.getMonth() == Calendar.DECEMBER && chineseCalender.getDay() == 31) {
        return true;
    }
    return chineseCalender.getMonth() == Calendar.JANUARY && chineseCalender.getDay() == 1;
}
 
Example 4
/**
 * 此日期所表示的一周中的某一天。
 *
 * @param date
 * @param format
 * @return String (format+day)
 */
@SuppressWarnings("deprecation")
public static String formatDateToWeek(Date date, String format) {
	if (date == null) {
		return null;
	}
	if (format == null || format.equals("")) {
		format = "星期";
	}
	int day = date.getDay();
	String week = format;
	switch (day) {
	case 1:
		week += "一";
		break;
	case 2:
		week += "二";
		break;
	case 3:
		week += "三";
		break;
	case 4:
		week += "四";
		break;
	case 5:
		week += "五";
		break;
	case 6:
		week += "六";
		break;
	case 0:
		week += "日";
		break;
	default:
		break;
	}
	return week;
}
 
Example 5
Source Project: unitime   File: SingleDateSelector.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
static int weekNumber(int year, int month) {
	Date d = new Date(year - 1900, month - 1, 1);
	while (d.getDay() != CalendarUtil.getStartingDayOfWeek()) d.setDate(d.getDate() - 1);
	// ISO 8601: move to the next Thursday
	while (d.getDay() != 4) d.setDate(d.getDate() + 1);
	int y = d.getYear();
	int week = 0;
	while (d.getYear() == y) { d.setDate(d.getDate() - 7); week += 1; }
	return week;
}
 
Example 6
Source Project: AutoTest   File: TimeUtils.java    License: MIT License 5 votes vote down vote up
private static boolean isThisWeek(Date date) {
    Date now = new Date();
    if ((date.getYear() == now.getYear()) && (date.getMonth() == now.getMonth())) {
        if (now.getDay() - date.getDay() < now.getDay() && now.getDate() - date.getDate() > 0 && now.getDate() - date.getDate() < 7) {
            return true;
        }
    }
    return false;
}
 
Example 7
Source Project: Swface   File: StickyListAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private int[] getSectionIndices() {
	ArrayList<Integer> sectionIndices = new ArrayList<Integer>();
	if(mSignLogList.isEmpty()){
		return null;
	}
	Date lastFirstDate = DateUtil.getDateFromLong(mSignLogList.get(0).getTime());
	sectionIndices.add(0);
	int year = lastFirstDate.getYear();
	int month = lastFirstDate.getMonth();
	int date = lastFirstDate.getDay();
	for (int i = 1; i < mSignLogList.size(); i++) {
		Date dateTemp = DateUtil.getDateFromLong(mSignLogList.get(i).getTime());
		int year_temp = dateTemp.getYear();
		int month_temp = dateTemp.getMonth();
		int date_temp = dateTemp.getDay();
		if (year == year_temp && month_temp == month && date_temp == date) {
			continue;
		} else {
			lastFirstDate = DateUtil.getDateFromLong(mSignLogList.get(i).getTime());
			year = lastFirstDate.getYear();
			month = lastFirstDate.getMonth();
			date = lastFirstDate.getDay();
			sectionIndices.add(i);
		}
	}
	int[] sections = new int[sectionIndices.size()];
	for (int i = 0; i < sectionIndices.size(); i++) {
		sections[i] = sectionIndices.get(i);
	}
	return sections;
}
 
Example 8
Source Project: letv   File: StringUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static int getLocalWeekDay() {
    Calendar.getInstance().get(7);
    Date date = new Date(System.currentTimeMillis());
    if (date.getDay() == 0) {
        return 7;
    }
    return date.getDay();
}
 
Example 9
Source Project: DAFramework   File: TextUtils.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static String getShortTimeText(Long oldTime) {
	Date time = parseDate(oldTime, TimeFormat);
	Date now = new Date();
	String format = "yyyy-MM-dd HH:mm";
	if (time.getYear() == now.getYear()) {
		format = format.substring("yyyy-".length());
		if (time.getMonth() == now.getMonth() && time.getDay() == now.getDay()) {
			format = format.substring("MM-dd ".length());
		}
	}
	return formatDate(time, format);
}
 
Example 10
private void saveImage() {
    try {
        File root = Environment.getExternalStorageDirectory();
        if (root.canWrite()) {
            Date d = new Date();
            File imageLoc = new File(root, "com/duy/example/com.duy.calculator/graph/" + d.getMonth() + d.getDay() + d.getHours() + d.getMinutes() + d.getSeconds() + ".png");
            FileOutputStream out = new FileOutputStream(imageLoc);
        } else {
            Toast.makeText(GraphActivity.this, getString(R.string.cannotwrite), Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        Toast.makeText(GraphActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
    }
}
 
Example 11
Source Project: wES   File: TextUtils.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static String getShortTimeText(Long oldTime) {
	Date time = parseDate(oldTime, TimeFormat);
	Date now = new Date();
	String format = "yyyy-MM-dd HH:mm";
	if (time.getYear() == now.getYear()) {
		format = format.substring("yyyy-".length());
		if (time.getMonth() == now.getMonth() && time.getDay() == now.getDay()) {
			format = format.substring("MM-dd ".length());
		}
	}
	return formatDate(time, format);
}
 
Example 12
@Override
protected String getFileName(Date date) {
    if (date.getDay() != 0) {
        return null;
    }
    String name = "pi" + nf.format(date.getYear() - 100) +
        nf.format(date.getMonth() + 1) + nf.format(date.getDate()) +
        ".puz";

    return name;
}
 
Example 13
@Override
protected String getFileName(Date date) {
    if (date.getDay() != 0) {
        return null;
    }
    String name = "boston_" + nf.format(date.getMonth() + 1) +
        nf.format(date.getDate()) + (date.getYear() + 1900) + ".puz";
    return name;
}
 
Example 14
@Override
protected String getFileName(Date date) {
    if (date.getDay() != 3) {
        return null;
    }
    return "av" + this.nf.format(date.getYear() - 100)
            + this.nf.format(date.getMonth() + 1) + this.nf.format(date.getDate())
            + ".puz";
}
 
Example 15
@Override
protected String getFileName(Date date) {
    if (date.getDay() != 5) {
        return null;
    }
    String name = "vv" + (date.getYear() - 100) +
        nf.format(date.getMonth() + 1) + nf.format(date.getDate()) +
        ".puz";

    return name;
}
 
Example 16
private boolean easterDay() {
    int year = new Date().getYear();
    int a = year % 19,
            b = year / 100,
            c = year % 100,
            d = b / 4,
            e = b % 4,
            g = (8 * b + 13) / 25,
            h = (19 * a + b - d - g + 15) % 30,
            j = c / 4,
            k = c % 4,
            m = (a + 11 * h) / 319,
            r = (2 * e + 2 * j - k - h + m + 32) % 7,
            n = (h - m + r + 90) / 25,
            p = (h - m + r + n + 19) % 32;

    int result;
    switch (n) {
        case 1:
            result = Calendar.JANUARY;
            break;
        case 2:
            result = Calendar.FEBRUARY;
            break;
        case 3:
            result = Calendar.MARCH;
            break;
        case 4:
            result = Calendar.APRIL;
            break;
        case 5:
            result = Calendar.MAY;
            break;
        case 6:
            result = Calendar.JUNE;
            break;
        case 7:
            result = Calendar.JULY;
            break;
        case 8:
            result = Calendar.AUGUST;
            break;
        case 9:
            result = Calendar.SEPTEMBER;
            break;
        case 10:
            result = Calendar.OCTOBER;
            break;
        case 11:
            result = Calendar.NOVEMBER;
            break;
        case 12:
            result = Calendar.DECEMBER;
            break;
        default:
            throw new IllegalStateException("Unexpected value: " + n);
    }
    Date eaterDay = new Date(year, result, p);
    Date currentDate = new Date(System.currentTimeMillis());
    if (currentDate.getYear() == eaterDay.getYear()) {
        if (currentDate.getMonth() == eaterDay.getMonth()) {
            return currentDate.getDay() == eaterDay.getDay();
        }
    }
    return false;
}
 
Example 17
/**
 *
 * @param startTime
 *            开始时间
 * @param finishTime
 *            结束时间
 * @param formater
 *            当前时间格式
 * @return
 */
@SuppressWarnings("deprecation")
public static String formatDateTime(String startTime, String finishTime,
		String formater) {
	if (isEmpty(startTime) || isEmpty(finishTime)) {
		return "";
	}
	StringBuffer sb = new StringBuffer("");
	if (formater == null || formater.length() == 0) {
		formater = DATEFORMAT;
	}
	if (startTime.length() < formater.length()
			&& finishTime.length() < formater.length()) {
		formater = "yyyy-MM-dd";
	}
	String zero = "00:00", zeroTime = " HH:mm";
	String stime = startTime.substring(startTime.length() - 5,
			startTime.length());
	String etime = startTime.substring(finishTime.length() - 5,
			finishTime.length());
	if (!isEmpty(stime) && !isEmpty(etime) && stime.equals(etime)
			&& stime.equals(zero)) {
		zeroTime = "";
	}
	Date date1 = DateFormatUtils.formatStrToDate(startTime, formater);
	Date date2 = DateFormatUtils.formatStrToDate(finishTime, formater);
	if (date1 != null && date2 != null) {
		if (date1.getYear() == date2.getYear()) {
			if (date1.getMonth() == date2.getMonth()
					&& date1.getDay() == date2.getDay()) {
				// 09月12日 13:00 MM月dd日 HH:mm
				sb.append(DateFormatUtils.formatDateStr(startTime,
						formater, "yyyy年MM月dd日 HH:mm"));
				sb.append("-");
				sb.append(DateFormatUtils.formatDateStr(finishTime,
						formater, " HH:mm"));
			} else {// 跨天、跨月的09月12日 13:00-09月13日14:00
					// String sf="yyyy年MM月dd日"+zeroTime;
				sb.append(DateFormatUtils.formatDateStr(startTime,
						formater, "yyyy年MM月dd日"));
				sb.append("-");
				sb.append(DateFormatUtils.formatDateStr(finishTime,
						formater, " dd日"));
			}
		} else {// 2012年12月31日 13:00-2013年01月01日14:00 yyyy年MM月dd日 HH:mm
			String sf = "yyyy年MM月dd日" + zeroTime;
			sb.append(DateFormatUtils
					.formatDateStr(startTime, formater, sf));
			sb.append("-");
			sb.append(DateFormatUtils.formatDateStr(finishTime, formater,
					sf));
		}
	}
	return new String(sb);
}
 
Example 18
Source Project: hasting   File: RpcUtils.java    License: MIT License 4 votes vote down vote up
@SuppressWarnings("deprecation")
public static long getMinute(Date date){
	GregorianCalendar calendar = new GregorianCalendar(1900+date.getYear(),date.getMonth(),date.getDay(),date.getHours(),date.getMinutes());
	return calendar.getTimeInMillis();
}
 
Example 19
public static String dateTimeText(long timeInMs) {
    Date d = new Date(timeInMs);
    return "" + d.getDay() + "." + d.getMonth() + "." + d.getYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
}
 
Example 20
public void setDate(View view, boolean completed, String due_on, long id) {
    TextView dueOn = (TextView) view.findViewById(R.id.due_on);
    Log.i(TAG, "due_on:" + due_on);

    Date date = new Date();
    Date now = new Date();

    try {
        date = sdf.parse(due_on);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    DateTime dt = new DateTime(date);
    int month = dt.getMonthOfYear();
    int dayOfMonth = dt.getDayOfMonth();
    int year = dt.getYear();
    String localizedMonth = months[month - 1];
    due_on = String.format("%02d %s %04d", dayOfMonth, localizedMonth, year);

    Log.i(TAG, "due_on(formatted):" + due_on);
    dueOn.setText(due_on);
    if (completed) {
        dueOn.setTextColor(getResources().getColor(R.color.complete));
    } else if (now.getDay() == date.getDay()
            && now.getMonth() == date.getMonth()
            && now.getYear() == date.getYear()) {
        if (now.after(date)) {
            dueOn.setTextColor(getResources().getColor(R.color.past_due));
            Log.w(TAG, "DUE TODAY-PAST DUE:" + id);
        } else {
            Log.w(TAG, "DUE TODAY:" + id);
            dueOn.setTextColor(getResources().getColor(R.color.due_today));
        }
    } else if (now.after(date)) {
        dueOn.setTextColor(getResources().getColor(R.color.past_due));
        Log.w(TAG, "PAST DUE DATE:" + id);
    } else {
        Log.i(TAG, "due date ok:" + id);
        dueOn.setTextColor(getResources().getColor(android.R.color.white));
    }
}