本文整理匯總了Java中java.util.Date.before方法的典型用法代碼示例。如果您正苦於以下問題:Java Date.before方法的具體用法?Java Date.before怎麽用?Java Date.before使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Date
的用法示例。
在下文中一共展示了Date.before方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: compararFechaHora
import java.util.Date; //導入方法依賴的package包/類
public static boolean compararFechaHora(EditText f1, EditText h1, String fec1, String fec2){
Log.d("FECHAS", fec1 + " " + fec2);
Date d1 = DateUtilities.stringToDate(fec1);
Date d2 = DateUtilities.stringToDate(fec2);
if(d2.before(d1)){
((TextInputLayout)f1.getParent().getParent()).setErrorEnabled(true);
((TextInputLayout)f1.getParent().getParent()).setError("La fecha de fin no puede ser posterior a la de inicio.");
((TextInputLayout)h1.getParent().getParent()).setErrorEnabled(true);
((TextInputLayout)h1.getParent().getParent()).setError("");
return false;
}
else{
return true;
}
}
示例2: getToSync
import java.util.Date; //導入方法依賴的package包/類
/**
* Returns a {@link List} of {@link Synchronizer} whose cron expression is
* triggered between the given parameters.
* @param start the /start/ Date (exclusive).
* @param end the /end/ Date (inclusive).
* @return a {@link List} of {@link Synchronizer}.
*/
private List<StatSync> getToSync (Date start, Date end) throws InterruptedException
{
List<StatSync> res = new LinkedList<> ();
lockSyncMap.lockInterruptibly ();
try
{
for (Map.Entry<CronSchedule, List<StatSync>> e: synchronizers.entrySet ())
{
Date next = e.getKey ().cronExpression.getNextValidTimeAfter (start);
if (next.before (end) || next.equals (end))
{
res.addAll (e.getValue ());
}
}
}
finally
{
lockSyncMap.unlock ();
}
return res;
}
示例3: getCompletionStatus
import java.util.Date; //導入方法依賴的package包/類
@Override
public ToolCompletionStatus getCompletionStatus(Long learnerId, Long toolSessionId) {
ChatUser learner = getUserByUserIdAndSessionId(learnerId, toolSessionId);
if (learner == null) {
return new ToolCompletionStatus(ToolCompletionStatus.ACTIVITY_NOT_ATTEMPTED, null, null);
}
Date startDate = null;
Date endDate = learner.getLastPresence();
List<ChatMessage> messages = getMessagesForUser(learner);
for ( ChatMessage message : messages ) {
Date sendDate = message.getSendDate();
if ( sendDate != null ) {
if ( startDate == null || sendDate.before(startDate) )
startDate = sendDate;
if ( endDate == null || sendDate.after(endDate) )
endDate = sendDate;
}
}
if (learner.isFinishedActivity())
return new ToolCompletionStatus(ToolCompletionStatus.ACTIVITY_COMPLETED, startDate, endDate);
else
return new ToolCompletionStatus(ToolCompletionStatus.ACTIVITY_ATTEMPTED, startDate, null);
}
示例4: inPast
import java.util.Date; //導入方法依賴的package包/類
/**
* Checks whether or not a date has already past (IE: March 3, 1990).
*
* @param dateRaw The date to check in format (yyyy/MM/dd-HH:mm:ss).
* @param timezone The timezone of the calendar this event is for.
* @return <code>true</code> if the date is in the past, otherwise <code>false</code>.
*/
public static boolean inPast(String dateRaw, TimeZone timezone) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
sdf.setTimeZone(timezone);
Date dateObj = sdf.parse(dateRaw);
Date now = new Date(System.currentTimeMillis());
return dateObj.before(now);
} catch (ParseException e) {
return true;
}
}
示例5: nowDateBetweenStartDateAndEndDate
import java.util.Date; //導入方法依賴的package包/類
/**
* 判斷當前時間是否在在兩個時間之間
*
* @param startDate
* 開始時間
* @param endDate
* 結束時間
* @return
*/
public static boolean nowDateBetweenStartDateAndEndDate(Date startDate, Date endDate) {
boolean bool = false;
Date curDate = new Date();
if (curDate.after(startDate) && curDate.before(endDate)) {
bool = true;
}
return bool;
}
示例6: checkRefreshRequired
import java.util.Date; //導入方法依賴的package包/類
protected boolean checkRefreshRequired(Date cachedAt) {
if (cachedAt == null) {
return true;
}
Date now = new Date();
Date notOlderThen = new Date(now.getTime() - refreshMetadataIfOlderThenSec
* 1000);
if (cachedAt.before(notOlderThen)) {
return true;
}
return false;
}
示例7: buildTime
import java.util.Date; //導入方法依賴的package包/類
private static Date buildTime() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 11);//時
calendar.set(Calendar.MINUTE, 9);//分
calendar.set(Calendar.SECOND, 0);//秒
Date time = calendar.getTime();
if (time.before(new Date())) {
//若果當前時間已經是淩晨1點後,需要往後加1天,否則任務會立即執行。
//很多係統往往係統啟動時就需要立即執行一次任務,但下麵又需要每天淩晨1點執行,怎麽辦呢?
//很簡單,就在係統初始化話時單獨執行一次任務(不需要用定時器,隻是執行那段任務的代碼)
time = addDay(time, 1);
}
return time;
}
示例8: getEndHour
import java.util.Date; //導入方法依賴的package包/類
/**
* Recuperar hora com minutos e segundos iguais a 59.
* @param date informar uma data válida.
*/
public static Date getEndHour(Date date, boolean untilToday) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.set(Calendar.MILLISECOND, 999);
Date dateToday = new Date();
if (untilToday && (dateToday.before(calendar.getTime()))) {
calendar.setTime(dateToday);
}
return calendar.getTime();
}
示例9: future
import java.util.Date; //導入方法依賴的package包/類
/**
* Build a validator that checks that given {@link Date} value is in the future.
* <p>
* Supported data types: {@link Date}
* </p>
* @param <T> Validator type
* @param includeTime Whether to include time in validation. If <code>false</code>, only year/month/day are
* considered.
* @param message Validation error message
* @param messageCode Optional validation error message localization code
* @return Validator
*/
@SuppressWarnings("serial")
static <T extends Date> Validator<T> future(boolean includeTime, String message, String messageCode) {
return new BuiltinValidator<T>() {
@Override
public void validate(T v) throws ValidationException {
if (v != null) {
if (!includeTime) {
Date today = CalendarUtils.floorTime(Calendar.getInstance()).getTime();
Date date = CalendarUtils.floorTime(v);
if (today.equals(date) || date.before(today)) {
throw new ValidationException(message, messageCode);
}
} else {
if (v.getTime() <= System.currentTimeMillis()) {
throw new ValidationException(message, messageCode);
}
}
}
}
@Override
public Optional<ValidatorDescriptor> getDescriptor() {
return Optional.of(ValidatorDescriptor.builder().future().build());
}
};
}
示例10: isTokenExpired
import java.util.Date; //導入方法依賴的package包/類
private Boolean isTokenExpired(String token) {
final Date expiration = getExpirationDateFromToken(token);
return expiration.before(timeProvider.now());
}
示例11: contains
import java.util.Date; //導入方法依賴的package包/類
/**
* Gibt an, ob das gegebene Datum innerhalb des Zeitraumes ist, d.h. date >= datumVon && date <= datumBis
*/
public boolean contains(Date date) {
return !date.before(von) && !date.after(bis);
}
示例12: isTimeBetween
import java.util.Date; //導入方法依賴的package包/類
private static boolean isTimeBetween(String fromTime, String toTime, String nowTime) throws ParseException {
String reg = "^([0-1][0-9]|2[0-3]):([0-5][0-9])$";
if (fromTime.matches(reg) && toTime.matches(reg) && nowTime.matches(reg)) {
boolean valid;
Date startTime = new SimpleDateFormat("HH:mm", Locale.US).parse(fromTime);
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(startTime);
Date currentTime = new SimpleDateFormat("HH:mm", Locale.US).parse(nowTime);
Calendar currentCalendar = Calendar.getInstance();
currentCalendar.setTime(currentTime);
Date endTime = new SimpleDateFormat("HH:mm", Locale.US).parse(toTime);
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(endTime);
if (currentTime.compareTo(endTime) < 0) {
currentCalendar.add(Calendar.DATE, 1);
currentTime = currentCalendar.getTime();
}
if (startTime.compareTo(endTime) < 0) {
startCalendar.add(Calendar.DATE, 1);
startTime = startCalendar.getTime();
}
if (currentTime.before(startTime)) {
valid = false;
} else {
if (currentTime.after(endTime)) {
endCalendar.add(Calendar.DATE, 1);
endTime = endCalendar.getTime();
}
valid = currentTime.before(endTime);
}
return valid;
} else {
throw new IllegalArgumentException("Not a valid time, expecting HH:mm format");
}
}
示例13: isTokenExpired
import java.util.Date; //導入方法依賴的package包/類
private Boolean isTokenExpired(String token) {
final Date expiration = getExpirationDateFromToken(token);
return expiration.before(new Date());
}
示例14: getTimeShowString
import java.util.Date; //導入方法依賴的package包/類
public static String getTimeShowString(long milliseconds, boolean abbreviate) {
String dataString;
String timeStringBy24;
Date currentTime = new Date(milliseconds);
Date today = new Date();
Calendar todayStart = Calendar.getInstance();
todayStart.set(Calendar.HOUR_OF_DAY, 0);
todayStart.set(Calendar.MINUTE, 0);
todayStart.set(Calendar.SECOND, 0);
todayStart.set(Calendar.MILLISECOND, 0);
Date todaybegin = todayStart.getTime();
Date yesterdaybegin = new Date(todaybegin.getTime() - 3600 * 24 * 1000);
Date preyesterday = new Date(yesterdaybegin.getTime() - 3600 * 24 * 1000);
if (!currentTime.before(todaybegin)) {
dataString = "今天";
} else if (!currentTime.before(yesterdaybegin)) {
dataString = "昨天";
} else if (!currentTime.before(preyesterday)) {
dataString = "前天";
} else if (isSameWeekDates(currentTime, today)) {
dataString = getWeekOfDate(currentTime);
} else {
SimpleDateFormat dateformatter = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
dataString = dateformatter.format(currentTime);
}
SimpleDateFormat timeformatter24 = new SimpleDateFormat("HH:mm", Locale.getDefault());
timeStringBy24 = timeformatter24.format(currentTime);
if (abbreviate) {
if (!currentTime.before(todaybegin)) {
return getTodayTimeBucket(currentTime);
} else {
return dataString;
}
} else {
return dataString + " " + timeStringBy24;
}
}
示例15: isCreatedBeforeLastPasswordReset
import java.util.Date; //導入方法依賴的package包/類
private Boolean isCreatedBeforeLastPasswordReset(Date created, Date lastPasswordReset) {
return (lastPasswordReset != null && created.before(lastPasswordReset));
}