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

The following examples show how to use java.util.Date#getDay() . 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 check out the related API usage on the sidebar.
Example 1
Source File: Downloaders.java    From shortyz with GNU General Public License v3.0 6 votes vote down vote up
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 2
Source File: FunnyEasterEgg.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@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 3
Source File: GraphActivity.java    From ncalc with GNU General Public License v3.0 5 votes vote down vote up
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 4
Source File: InkwellDownloader.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
@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 5
Source File: AVClubDownloader.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
@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 6
Source File: BostonGlobeDownloader.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
@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 7
Source File: PhillyDownloader.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
@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 8
Source File: TextUtils.java    From wES with 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 9
Source File: TextUtils.java    From DAFramework with 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
Source File: StringUtils.java    From letv with 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 11
Source File: StickyListAdapter.java    From Swface with 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 12
Source File: TimeUtils.java    From AutoTest with 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 13
Source File: SingleDateSelector.java    From unitime with 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 14
Source File: DateFormatUtils.java    From Alibaba-Android-Certification with MIT License 5 votes vote down vote up
/**
 * 此日期所表示的一周中的某一天。
 *
 * @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 15
Source File: FunnyEasterEgg.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
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 16
Source File: RpcUtils.java    From hasting with 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 17
Source File: DateFormatUtils.java    From Alibaba-Android-Certification with MIT License 4 votes vote down vote up
/**
 *
 * @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 File: WearUtil.java    From AndroidAPS with GNU Affero General Public License v3.0 4 votes vote down vote up
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 19
Source File: EncounterTaskListFragment.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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));
    }
}
 
Example 20
Source File: FunnyEasterEgg.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
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;
}