本文整理汇总了Java中java.util.Calendar.after方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.after方法的具体用法?Java Calendar.after怎么用?Java Calendar.after使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Calendar
的用法示例。
在下文中一共展示了Calendar.after方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDaysBetween
import java.util.Calendar; //导入方法依赖的package包/类
/**
* Calculates the number of days between two calendar days in a manner
* which is independent of the Calendar type used.
*
* @param d1 The first date.
* @param d2 The second date.
*
* @return The number of days between the two dates. Zero is
* returned if the dates are the same, one if the dates are
* adjacent, etc. The order of the dates
* does not matter, the value returned is always >= 0.
* If Calendar types of d1 and d2
* are different, the result may not be accurate.
*/
public static int getDaysBetween( Calendar d1, Calendar d2 ) {
if ( d1.after(d2) ) {
// swap dates so that d1 is start and d2 is end
Calendar swap = d1;
d1 = d2;
d2 = swap;
}
long days = (d2.getTimeInMillis() - d1.getTimeInMillis()) / (1000 * 60 * 60 * 24);
return (int) days;
// int days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR);
// int y2 = d2.get(Calendar.YEAR);
// if (d1.get(Calendar.YEAR) != y2) {
// d1 = (Calendar) d1.clone();
// do {
// days += d1.getActualMaximum(Calendar.DAY_OF_YEAR);
// d1.add(Calendar.YEAR, 1);
// } while (d1.get(Calendar.YEAR) != y2);
// }
// return days;
}
示例2: formatDateDiff
import java.util.Calendar; //导入方法依赖的package包/类
public static String formatDateDiff(Calendar fromDate, Calendar toDate) {
boolean future = false;
if (toDate.equals(fromDate)) {
return I18N.tr("now");
}
if (toDate.after(fromDate)) {
future = true;
}
StringBuilder sb = new StringBuilder();
int[] types = { Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND };
String[] names = {
I18N.tr("year"), I18N.tr("years"),
I18N.tr("month"), I18N.tr("months"),
I18N.tr("day"), I18N.tr("days"),
I18N.tr("hour"), I18N.tr("hours"),
I18N.tr("minute"), I18N.tr("minutes"),
I18N.tr("second"), I18N.tr("seconds")
};
int accuracy = 0;
for (int i = 0; i < types.length; i++) {
if (accuracy > 2) {
break;
}
int diff = dateDiff(types[i], fromDate, toDate, future);
if (diff > 0) {
accuracy++;
sb.append(" ").append(diff).append(" ").append(names[i * 2 + (diff > 1 ? 1 : 0)]);
}
}
if (sb.length() == 0) {
return "now";
}
return sb.toString().trim();
}
示例3: compareTo
import java.util.Calendar; //导入方法依赖的package包/类
@Override
public int compareTo(Object o) {
Calendar time = Calendar.getInstance();
time.getTimeInMillis();
Calendar other = Calendar.getInstance();
other.getTimeInMillis();
time.set(Calendar.HOUR_OF_DAY, this.hour);
time.set(Calendar.MINUTE, this.minute);
NotificationSetting otherNs = (NotificationSetting) o;
other.set(Calendar.HOUR_OF_DAY, otherNs.hour);
other.set(Calendar.MINUTE, otherNs.minute);
if (time.before(other)) {
return -1;
} else if (time.after(other)) {
return 1;
}
return 0;
}
示例4: isCurrentYear
import java.util.Calendar; //导入方法依赖的package包/类
/**
* Description:判断是不是进年
*
* @param c
* @return
* @return boolean
* @author name:拜力文
* <p>=
* ===========================================
* </p>
* Modified No: Modified By: Modified Date: Modified Description:
* <p>=
* ===========================================
* </p>
**/
public static boolean isCurrentYear(Calendar c) {
Calendar today_start = Calendar
.getInstance(TimeZone.getTimeZone(GMT_8));
today_start.set(Calendar.HOUR_OF_DAY, 0);
today_start.set(Calendar.MINUTE, 0);
today_start.set(Calendar.MONTH, 0);
today_start.set(Calendar.DAY_OF_MONTH, 1);
today_start.set(Calendar.SECOND, 0);
System.out.println(dateFormatFromCalender(today_start,
DateFormateUtil.FORMAT_FULL_DATE_TIME_WITH_SYMBOL));
Calendar today_end = Calendar.getInstance(TimeZone.getTimeZone(GMT_8));
today_end.set(Calendar.HOUR_OF_DAY, 23);
today_end.set(Calendar.MINUTE, 59);
today_end.set(Calendar.MONTH, 11);
today_end.set(Calendar.DAY_OF_MONTH, 31);
today_end.set(Calendar.SECOND, 59);
System.out.println(dateFormatFromCalender(today_end,
DateFormateUtil.FORMAT_FULL_DATE_TIME_WITH_SYMBOL));
return c.before(today_end) && c.after(today_start);
}
示例5: Test4738710
import java.util.Calendar; //导入方法依赖的package包/类
/**
* 4738710: API: Calendar comparison methods should be improved
*/
public void Test4738710() {
Calendar cal0 = new GregorianCalendar(2003, SEPTEMBER, 30);
Comparable<Calendar> cal1 = new GregorianCalendar(2003, OCTOBER, 1);
Calendar cal2 = new GregorianCalendar(2003, OCTOBER, 2);
if (!(cal1.compareTo(cal0) > 0)) {
errln("!(cal1 > cal0)");
}
if (!(cal1.compareTo(cal2) < 0)) {
errln("!(cal1 < cal2)");
}
if (cal1.compareTo(new GregorianCalendar(2003, OCTOBER, 1)) != 0) {
errln("cal1 != new GregorianCalendar(2003, OCTOBER, 1)");
}
if (cal0.after(cal2)) {
errln("cal0 shouldn't be after cal2");
}
if (cal2.before(cal0)) {
errln("cal2 shouldn't be before cal0");
}
if (cal0.after(0)) {
errln("cal0.after() returned true with an Integer.");
}
if (cal0.before(0)) {
errln("cal0.before() returned true with an Integer.");
}
if (cal0.after(null)) {
errln("cal0.after() returned true with null.");
}
if (cal0.before(null)) {
errln("cal0.before() returned true with null.");
}
}
示例6: getEventsCompleted
import java.util.Calendar; //导入方法依赖的package包/类
/**
* Gets the number of events that have been completed.
* That is, the number of events corresponding to the schedule that
* have occurred after the habit start date.
* Ex: Schedule = Mon,Tue,Wed. Events: Mon,Wed,Fri.
* Would return 2
* @return number of completed events.
*/
public int getEventsCompleted(){
if (events==null || events.isEmpty()) return 0;
if (schedule==null || schedule.isEmpty()) return 0;
if (startDate==null) return 0;
int total = 0;
Calendar cal = Calendar.getInstance();
Calendar start = Calendar.getInstance();
start.setTime(startDate);
for (HabitEvent event : events){
Date d = event.getDate();
if (d==null) continue;
cal.setTime(d);
if(cal.after(start) && schedule.contains(cal.get(Calendar.DAY_OF_WEEK))){
total++;
}
}
return total;
}
示例7: getLatestHabitEventDate
import java.util.Calendar; //导入方法依赖的package包/类
/**
* Gets the most recent habit event date
* @param h Habit
* @return Most recent habit event date
*/
private Calendar getLatestHabitEventDate(Habit h){
ArrayList<HabitEvent> events = h.getEvents();
if (events==null) return null;
if (events.isEmpty()) return null;
Calendar latest = Calendar.getInstance();
latest.setTime(events.get(0).getDate());
if (events.size()==1) return latest;
Calendar test = Calendar.getInstance();
Calendar now = Calendar.getInstance();
for (HabitEvent event : events){
if (event.getDate()==null) continue;
test.setTime(event.getDate());
if (test.after(latest)){
if (!test.after(now)){
latest.setTime(test.getTime());
}
}
}
return latest;
}
示例8: isNowBetween
import java.util.Calendar; //导入方法依赖的package包/类
/**
* 判断当前时间是否在两个时间段之内
*
* @param beginTime 开始时间
* @param endTime 结束时间
* @return
*/
public static boolean isNowBetween(String beginTime, String endTime) {
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
Date now = null;
Date begin = null;
Date end = null;
try {
now = df.parse(df.format(new Date()));
begin = df.parse(beginTime);
end = df.parse(endTime);
} catch (Exception e) {
e.printStackTrace();
}
Calendar nowCal = Calendar.getInstance();
nowCal.setTime(now);
Calendar beginCal = Calendar.getInstance();
beginCal.setTime(begin);
Calendar endCal = Calendar.getInstance();
endCal.setTime(end);
if (nowCal.after(beginCal) && nowCal.before(endCal)) {
return true;
} else {
return false;
}
}
示例9: befToday
import java.util.Calendar; //导入方法依赖的package包/类
public static boolean befToday(String timeStr) {
if(TextUtils.isEmpty(timeStr)) {
return false;
}
final Calendar calend = dateFormatFromString(timeStr, DateFormateUtil.FORMAT_FULL_DATE_TIME_WITH_SYMBOL);
Calendar today = Calendar.getInstance(TimeZone.getTimeZone(GMT_8));
today.setTime(new Date());
//差几天
if (today.after(calend) || isToday(calend)) {
return true;
}
return false;
}
示例10: checkBeforeAfter
import java.util.Calendar; //导入方法依赖的package包/类
/**
* Check if the first calendar is actually dated before the second calendar.
* @param before The first calendar with expected date before the second calendar.
* @param after The second calendar with expected date after the first calendar.
* @throws IllegalArgumentException If the first calendar is dated after the second calendar.
*/
private static void checkBeforeAfter(Calendar before, Calendar after) {
if (before.after(after)) {
throw new IllegalArgumentException(
"The first calendar should be dated before the second calendar.");
}
}
示例11: getDateValidity
import java.util.Calendar; //导入方法依赖的package包/类
/**
* Called when a date is selected from DatePicker.
*
* @param view Returns the calling view
* @param date Selected date
* @return {@code true} if the selected date is valid. {@code false} Otherwise.
*/
@Override
public boolean getDateValidity(CustomDateView view, Calendar date) {
switch (view.getId()) {
case R.id.activity_main_date_of_birth:
Calendar today = Calendar.getInstance();
today.add(Calendar.YEAR, -18);
return today.after(date);
}
return false;
}
示例12: formatTime
import java.util.Calendar; //导入方法依赖的package包/类
/**
* 时间转化为显示字符串
*
* @param timeStamp 单位为秒
*/
public static String formatTime(long timeStamp, boolean simple, Context context) {
if (timeStamp == 0) return "";
Calendar input = Calendar.getInstance();
input.setTimeInMillis(timeStamp);
String time = (new SimpleDateFormat("HH:mm:ss")).format(input.getTime());
String date = (new SimpleDateFormat(
"yyyy" + context.getResources().getString(R.string.time_year)
+ "MM" + context.getResources().getString(R.string.time_month)
+ "dd" + context.getResources().getString(R.string.time_day))).format(input.getTime());
Calendar calendar = Calendar.getInstance();
//当前时间在输入时间之前
if (!calendar.after(input)) {
return date;
}
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
if (calendar.before(input)) {
return String.format("%s %s", context.getResources().getString(R.string.time_today), simple ? "" : time);
}
calendar.add(Calendar.DAY_OF_MONTH, -1);
if (calendar.before(input)) {
return String.format("%s %s", context.getResources().getString(R.string.time_yesterday), simple ? "" : time);
}
calendar.set(Calendar.MONTH, Calendar.JANUARY);
calendar.set(Calendar.DAY_OF_MONTH, 1);
if (!simple && calendar.before(input)) {
date = (new SimpleDateFormat(
"MM" + context.getResources().getString(R.string.time_month)
+ "dd" + context.getResources().getString(R.string.time_day))).format(input.getTime());
}
return String.format("%s %s", date, simple ? "" : time);
}
示例13: formatDateTime
import java.util.Calendar; //导入方法依赖的package包/类
/**
* 格式化时间
* @param time
* @return
*/
public static String formatDateTime(String time) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if(time==null ||"".equals(time)){
return "";
}
Date date = null;
try {
date = format.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar current = Calendar.getInstance();
Calendar today = Calendar.getInstance(); //今天
today.set(Calendar.YEAR, current.get(Calendar.YEAR));
today.set(Calendar.MONTH, current.get(Calendar.MONTH));
today.set(Calendar.DAY_OF_MONTH,current.get(Calendar.DAY_OF_MONTH));
// Calendar.HOUR——12小时制的小时数 Calendar.HOUR_OF_DAY——24小时制的小时数
today.set( Calendar.HOUR_OF_DAY, 0);
today.set( Calendar.MINUTE, 0);
today.set(Calendar.SECOND, 0);
Calendar tomorrow = Calendar.getInstance(); //明天
tomorrow.set(Calendar.YEAR, current.get(Calendar.YEAR));
tomorrow.set(Calendar.MONTH, current.get(Calendar.MONTH));
tomorrow.set(Calendar.DAY_OF_MONTH,current.get(Calendar.DAY_OF_MONTH)+1);
tomorrow.set( Calendar.HOUR_OF_DAY, 0);
tomorrow.set( Calendar.MINUTE, 0);
tomorrow.set(Calendar.SECOND, 0);
Calendar afterTomorrow = Calendar.getInstance(); //后天
afterTomorrow.set(Calendar.YEAR, current.get(Calendar.YEAR));
afterTomorrow.set(Calendar.MONTH, current.get(Calendar.MONTH));
afterTomorrow.set(Calendar.DAY_OF_MONTH,current.get(Calendar.DAY_OF_MONTH)+2);
afterTomorrow.set( Calendar.HOUR_OF_DAY, 0);
afterTomorrow.set( Calendar.MINUTE, 0);
afterTomorrow.set(Calendar.SECOND, 0);
Calendar bigAfterTomorrow = Calendar.getInstance(); //大后天
bigAfterTomorrow.set(Calendar.YEAR, current.get(Calendar.YEAR));
bigAfterTomorrow.set(Calendar.MONTH, current.get(Calendar.MONTH));
bigAfterTomorrow.set(Calendar.DAY_OF_MONTH,current.get(Calendar.DAY_OF_MONTH)+3);
bigAfterTomorrow.set( Calendar.HOUR_OF_DAY, 0);
bigAfterTomorrow.set( Calendar.MINUTE, 0);
bigAfterTomorrow.set(Calendar.SECOND, 0);
current.setTime(date);
if(current.after(today) && current.before(tomorrow)){
return "今天 ";
}else if(current.before(afterTomorrow) && current.after(tomorrow)){
return "明天 ";
}else if(current.before(bigAfterTomorrow) && current.after(afterTomorrow)){
return "后天 ";
}else{
// int index = time.indexOf("-")+1;
// return time.substring(index, time.length());
return "";
}
}
示例14: isDateAfter
import java.util.Calendar; //导入方法依赖的package包/类
/**
* Check if one date is after another (to the day).
* If the days are the same, return true.
* @param before the date supposedly int the past
* @param after the date supposedly after before
* @return True if 'after' is after 'before', otherwise false.
*/
public static boolean isDateAfter(Date before, Date after){
Calendar b = Calendar.getInstance();
b.setTime(before);
Calendar a = Calendar.getInstance();
a.setTime(after);
if (a.get(Calendar.YEAR) == b.get(Calendar.YEAR) && a.get(Calendar.DAY_OF_YEAR) == b.get(Calendar.DAY_OF_YEAR)) return false;
return a.after(b);
}
示例15: checkActivity
import java.util.Calendar; //导入方法依赖的package包/类
public void checkActivity() {
Calendar calendar = Calendar.getInstance();
ActivityList clone = (ActivityList) clone();
for (ActivityInfo info : clone) {
Calendar activity_end = Calendar.getInstance();
activity_end.setTime(info.getEndDate());
activity_end.add(Calendar.DAY_OF_MONTH, 1);
if (calendar.after(activity_end)) {
remove(info);
}
}
}