java.util.Date#getDay ( )源码实例Demo

下面列出了java.util.Date#getDay ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: QuickShop-Reremake   文件: FunnyEasterEgg.java
@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;
}
 
源代码2 项目: shortyz   文件: Downloaders.java
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);
    }
}
 
源代码3 项目: QuickShop-Reremake   文件: FunnyEasterEgg.java
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;
}
 
/**
 * 此日期所表示的一周中的某一天。
 *
 * @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;
}
 
源代码5 项目: unitime   文件: SingleDateSelector.java
@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;
}
 
源代码6 项目: AutoTest   文件: TimeUtils.java
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;
}
 
源代码7 项目: Swface   文件: StickyListAdapter.java
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;
}
 
源代码8 项目: letv   文件: StringUtils.java
public static int getLocalWeekDay() {
    Calendar.getInstance().get(7);
    Date date = new Date(System.currentTimeMillis());
    if (date.getDay() == 0) {
        return 7;
    }
    return date.getDay();
}
 
源代码9 项目: DAFramework   文件: TextUtils.java
@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);
}
 
源代码10 项目: ncalc   文件: GraphActivity.java
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();
    }
}
 
源代码11 项目: wES   文件: TextUtils.java
@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);
}
 
源代码12 项目: shortyz   文件: PhillyDownloader.java
@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;
}
 
源代码13 项目: shortyz   文件: BostonGlobeDownloader.java
@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;
}
 
源代码14 项目: shortyz   文件: AVClubDownloader.java
@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";
}
 
源代码15 项目: shortyz   文件: InkwellDownloader.java
@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;
}
 
源代码16 项目: QuickShop-Reremake   文件: FunnyEasterEgg.java
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;
}
 
/**
 *
 * @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);
}
 
源代码18 项目: hasting   文件: RpcUtils.java
@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();
}
 
源代码19 项目: AndroidAPS   文件: WearUtil.java
public static String dateTimeText(long timeInMs) {
    Date d = new Date(timeInMs);
    return "" + d.getDay() + "." + d.getMonth() + "." + d.getYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
}
 
源代码20 项目: sana.mobile   文件: EncounterTaskListFragment.java
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));
    }
}