本文整理匯總了Java中java.util.Date.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java Date.equals方法的具體用法?Java Date.equals怎麽用?Java Date.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Date
的用法示例。
在下文中一共展示了Date.equals方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDatesBetween
import java.util.Date; //導入方法依賴的package包/類
/**
* This function will return a list of dates which are between the start and end dates given.
*
* @param start : The start date.
* @param end : The end date.
* @return The list of dates.
*/
private List<Date> getDatesBetween(Date start, Date end) {
Date cursor = start;
Calendar cal = Calendar.getInstance();
List<Date> results = new ArrayList<>();
while (!cursor.equals(end)) {
results.add(cursor);
cal.setTime(cursor);
cal.add(Calendar.DATE, 1);
cursor = cal.getTime();
}
if (!results.contains(end)) {
results.add(end);
}
return results;
}
示例2: hasTaskChanged
import java.util.Date; //導入方法依賴的package包/類
@Override
public boolean hasTaskChanged(@NonNull TaskRepository taskRepository, @NonNull ITask task,
@NonNull TaskData taskData) {
Date changedAtTaskData = taskData.getAttributeMapper()
.getDateValue(taskData.getRoot().getAttribute(TaskAttribute.DATE_MODIFICATION));
Date changedAtTask = task.getModificationDate();
if (changedAtTask == null || changedAtTaskData == null)
return true;
if (!changedAtTask.equals(changedAtTaskData))
return true;
return false;
}
示例3: Test4165343
import java.util.Date; //導入方法依賴的package包/類
/**
* Adding 12 months behaves differently from adding 1 year
*/
public void Test4165343() {
GregorianCalendar calendar = new GregorianCalendar(1996, FEBRUARY, 29);
Date start = calendar.getTime();
logln("init date: " + start);
calendar.add(MONTH, 12);
Date date1 = calendar.getTime();
logln("after adding 12 months: " + date1);
calendar.setTime(start);
calendar.add(YEAR, 1);
Date date2 = calendar.getTime();
logln("after adding one year : " + date2);
if (date1.equals(date2)) {
logln("Test passed");
} else {
errln("Test failed");
}
}
示例4: getAirportWeather
import java.util.Date; //導入方法依賴的package包/類
public static Weather getAirportWeather(String date, String airportTo, String username, String password) {
//enable basic login
HttpHelper.setAuth(username,password);
HttpHelper.enableAuth(true);
JsonNode response = HttpHelper.connect("https://twcservice.mybluemix.net/api/weather/v3/location/point?iataCode="+ airportTo +"&language=en-US", "GET", null);
if (response == null) {
return null;
}
//query the data and get its lat and lon
String city = response.path("location").path("city").asText();
double lat = response.path("location").path("latitude").asDouble();
String latitude = Double.toString(lat);
double lon = response.path("location").path("longitude").asDouble();
String longitude = Double.toString(lon);
JsonNode response2 = HttpHelper.connect("https://twcservice.mybluemix.net/api/weather/v1/geocode/" + latitude + "/" + longitude + "/forecast/daily/10day.json", "GET", null);
HttpHelper.enableAuth(false);
JsonNode d10 = response2.get("forecasts");
try{
//query data and reformat it to match the Weather class
DateFormat dates = new SimpleDateFormat("yyyy-MM-dd");
Date future = dates.parse(date);
for (JsonNode day : d10) {
String[] days = day.path("fcst_valid_local").asText().split("T");
Date dayDate = dates.parse(days[0]);
if(future.equals(dayDate)){
String weath = day.path("day").path("phrase_22char").asText();
int temperture = day.path("day").path("temp").asInt();
String narrative = day.path("day").path("narrative").asText();
Weather weather = new Weather(date, city, weath, temperture, narrative);
return weather;
}
}
} catch (Exception e) {
e.printStackTrace();
}
//If we can't find the matching day, return null
return null;
}
示例5: isSatisfiedBy
import java.util.Date; //導入方法依賴的package包/類
/**
* Indicates whether the given date satisfies the cron expression. Note that
* milliseconds are ignored, so two Dates falling on different milliseconds
* of the same second will always have the same result here.
*
* @param date the date to evaluate
* @return a boolean indicating whether the given date satisfies the cron
* expression
*/
public boolean isSatisfiedBy(Date date) {
Calendar testDateCal = Calendar.getInstance(getTimeZone());
testDateCal.setTime(date);
testDateCal.set(Calendar.MILLISECOND, 0);
Date originalDate = testDateCal.getTime();
testDateCal.add(Calendar.SECOND, -1);
Date timeAfter = getTimeAfter(testDateCal.getTime());
return ((timeAfter != null) && (timeAfter.equals(originalDate)));
}
示例6: compute
import java.util.Date; //導入方法依賴的package包/類
@Override
protected Boolean compute(Date left, Date right) {
if (left == null && right == null) {
return true;
}
if (left == null || right == null) {
return false;
}
return left.equals(right);
}
示例7: applyMisfire
import java.util.Date; //導入方法依賴的package包/類
protected boolean applyMisfire(TriggerWrapper tw) {
long misfireTime = System.currentTimeMillis();
if (getMisfireThreshold() > 0) {
misfireTime -= getMisfireThreshold();
}
Date tnft = tw.trigger.getNextFireTime();
if (tnft == null || tnft.getTime() > misfireTime
|| tw.trigger.getMisfireInstruction() == Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY) {
return false;
}
Calendar cal = null;
if (tw.trigger.getCalendarName() != null) {
cal = retrieveCalendar(tw.trigger.getCalendarName());
}
signaler.notifyTriggerListenersMisfired((OperableTrigger)tw.trigger.clone());
tw.trigger.updateAfterMisfire(cal);
if (tw.trigger.getNextFireTime() == null) {
tw.state = TriggerWrapper.STATE_COMPLETE;
signaler.notifySchedulerListenersFinalized(tw.trigger);
synchronized (lock) {
timeTriggers.remove(tw);
}
} else if (tnft.equals(tw.trigger.getNextFireTime())) {
return false;
}
return true;
}
示例8: checkParseRfc822Date
import java.util.Date; //導入方法依賴的package包/類
private static boolean checkParseRfc822Date() throws ParseException {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat(
"EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
sdf.setTimeZone(new SimpleTimeZone(0, "GMT"));
String formatted = sdf.format(date);
Date expected = sdf.parse(formatted);
Date actual2 = new Date(DateUtils.rfc822DateFormat.parseMillis(formatted));
return expected.equals(actual2);
}
示例9: checkGeneralized
import java.util.Date; //導入方法依賴的package包/類
private static void checkGeneralized(Date d0, byte[] b, String text) throws Exception {
Date d1 = decodeGeneralized(b);
if( !d0.equals(d1) ) {
throw new Exception("GeneralizedTime " + text + " failed: " + d1.toGMTString());
} else {
System.out.println("GeneralizedTime " + text + " ok");
}
}
示例10: compareDateNullSafety
import java.util.Date; //導入方法依賴的package包/類
@SuppressWarnings("SimplifiableIfStatement")
public static boolean compareDateNullSafety(@Nullable Date first, @Nullable Date second) {
if (first == null)
return second == null;
else if (second == null)
return false;
else
return first.equals(second);
}
示例11: equals
import java.util.Date; //導入方法依賴的package包/類
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DBBlocksJournalProcess)) return false;
DBBlocksJournalProcess other = (DBBlocksJournalProcess) o;
Date xactStart = process.getQuery().getXactStart();
Date otherXactStart = other.getProcess().getQuery().getXactStart();
boolean isSameXactStart = xactStart == null ? otherXactStart == null : xactStart.equals(otherXactStart);
boolean isSamePid = process.getPid() == other.getProcess().getPid();
return isSameXactStart && isSamePid && childrenEquals(process.getChildren(), other.getProcess().getChildren());
}
示例12: checkParseIso8601Date
import java.util.Date; //導入方法依賴的package包/類
private static boolean checkParseIso8601Date() throws ParseException {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
sdf.setTimeZone(new SimpleTimeZone(0, "GMT"));
String formatted = sdf.format(date);
String alternative = DateUtils.iso8601DateFormat.print(date.getTime());
if (formatted.equals(alternative)) {
Date expectedDate = sdf.parse(formatted);
Date actualDate = DateUtils.doParseISO8601Date(formatted);
return expectedDate.equals(actualDate);
}
return false;
}
示例13: parseRangeAndUpdate
import java.util.Date; //導入方法依賴的package包/類
protected void parseRangeAndUpdate(Date startDate, Date endDate, String directory,
PostgreStorage storage, String market)
throws IOException, ParseException {
while (startDate.before(endDate) || startDate.equals(endDate)) {
parseAndUpdate(startDate, directory, storage, market);
startDate = DateUtils.addDays(startDate, 1);
}
}
示例14: read
import java.util.Date; //導入方法依賴的package包/類
public void read() throws Exception {
FTPClient ftpClient = new FTPClient();
ftpClient.setBufferSize(1024 * 1024);
ftpClient.setDefaultTimeout(1000);
ftpClient.setControlEncoding("UTF-8");
ftpClient.setDataTimeout(10000);
ZipFile zipFile = new ZipFile();
Parser parser = new Parser();
URL feedUrl = new URL("https://download.kortforsyningen.dk/sites/default/files/feeds/MATRIKELKORT_GML.xml");
SyndFeedInput input = new SyndFeedInput();
System.out.println("Henter Atom feed....\n");
SyndFeed feed = input.build(new XmlReader(feedUrl));
System.out.println("Feed Titel: " + feed.getTitle());
Date lastPublishedDate;
Date currentDate;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String fileName;
Integer elavsKode;
Track track = new Track();
String lastStr = track.getLastFromDb();
lastPublishedDate = sdf.parse(lastStr);
System.out.println("\nSidste entry: " + lastStr + "\n");
this.login(ftpClient);
for (SyndEntry entry : (List<SyndEntry>) feed.getEntries()) {
System.out.println("\n--------------\n");
currentDate = entry.getPublishedDate();
if (currentDate.before(lastPublishedDate) || currentDate.equals(lastPublishedDate)) {
break;
}
System.out.println("Published Date: " + entry.getPublishedDate() + "\n");
// Get the Links
for (SyndLinkImpl link : (List<SyndLinkImpl>) entry.getLinks()) {
System.out.println("Link: " + link.getHref());
fileName = link.getHref().split("/")[7];
elavsKode = Integer.valueOf(fileName.split("_")[0]);
track.storeInDb(currentDate.toString(), elavsKode);
// Get the file
this.c(ftpClient, fileName, zipFile);
// Get xml stream from zip-file
ZipInputStream zin = zipFile.getGml(fileName);
// Parse the xml and insert in database
parser.build(zin, elavsKode);
// Delete the file
File file = new File(fileName);
file.delete();
}
}
// logout the user, returned true if logout successfully
ftpClient.disconnect();
System.out.println("Alt hentet...");
System.out.println("FTP forbindelse afbrydes.");
}
示例15: removeDuplicates
import java.util.Date; //導入方法依賴的package包/類
/**
* Searches the database for duplicate entries and removes them accordingly.
*
* @return True if no duplicate entries were found or all duplicate entries were successfully removed from the database.
* False if a duplicate entry could not be removed.
*/
public boolean removeDuplicates() {
// DELETE FROM MyTable WHERE RowId NOT IN (SELECT MIN(RowId) FROM MyTable GROUP BY Col1, Col2, Col3);
// but we need a workaround for the or mapper
try {
PreparedQuery<VaultEntry> query
= vaultDao.queryBuilder().orderBy("timestamp", true)
.prepare();
CloseableIterator<VaultEntry> iterator = vaultDao.iterator(query);
Date startGenerationTimestamp = null;
List<VaultEntry> tmpList = new ArrayList<>();
List<Long> duplicateId = new ArrayList<>();
while (iterator.hasNext()) {
VaultEntry entry = iterator.next();
if (startGenerationTimestamp == null) {
// start up
startGenerationTimestamp = entry.getTimestamp();
tmpList.add(entry);
} else if (!startGenerationTimestamp
.equals(entry.getTimestamp())) {
// not same timestamp --> new line generation
startGenerationTimestamp = entry.getTimestamp();
tmpList.clear();
tmpList.add(entry);
} else {
// same timestamp --> check if it is a duplicate
for (VaultEntry item : tmpList) {
if (item.equals(entry)) {
// duplicate --> delete and move on
duplicateId.add(entry.getId());
break;
}
}
}
}
// delete duplicates
int lines = vaultDao.deleteIds(duplicateId);
LOG.log(Level.INFO, "Removed {0} duplicates", lines);
} catch (SQLException exception) {
LOG.log(Level.SEVERE, "Error while db query", exception);
return false;
}
return true;
}