本文整理匯總了Java中java.util.Calendar.clear方法的典型用法代碼示例。如果您正苦於以下問題:Java Calendar.clear方法的具體用法?Java Calendar.clear怎麽用?Java Calendar.clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Calendar
的用法示例。
在下文中一共展示了Calendar.clear方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: needsSilenceUpdate
import java.util.Calendar; //導入方法依賴的package包/類
public static boolean needsSilenceUpdate(long value) { //Silence Update
/*If one os those get executed no one else will be
until it reach the next week or month change usually.
*/
if (value < 1) //Is First Launch ---> Like Really???, Will you launch it some day???
return true;
if (!isTheSameYear(value)) //New Year Update
return true;
if (!isTheSameMonth(value)) //New Month Update
return true;
//Weekly update
Calendar current = Calendar.getInstance();
Calendar old = Calendar.getInstance();
old.clear();
old.setTimeInMillis(value);
return current.get(Calendar. WEEK_OF_YEAR) != old.get(Calendar. WEEK_OF_YEAR);
}
示例2: determineNextDateString
import java.util.Calendar; //導入方法依賴的package包/類
public String determineNextDateString() {
TimeZone LOCAL_TIMEZONE = TimeZone.getTimeZone("GMT");
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(LOCAL_TIMEZONE);
calendar.clear();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setCalendar(calendar);
Date date;
try {
date = dateFormat.parse(dateString);
} catch (ParseException e) {
throw new IllegalStateException("Could not parse shiftDate (" + this
+ ")'s dateString (" + dateString + ").");
}
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_YEAR, 1);
return dateFormat.format(calendar.getTime());
}
示例3: getLastMillisecond
import java.util.Calendar; //導入方法依賴的package包/類
/**
* Returns the last millisecond of the week, evaluated using the supplied
* calendar (which determines the time zone).
*
* @param calendar the calendar (<code>null</code> not permitted).
*
* @return The last millisecond of the week.
*
* @throws NullPointerException if <code>calendar</code> is
* <code>null</code>.
*/
public long getLastMillisecond(Calendar calendar) {
Calendar c = (Calendar) calendar.clone();
c.clear();
c.set(Calendar.YEAR, this.year);
c.set(Calendar.WEEK_OF_YEAR, this.week + 1);
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
c.set(Calendar.HOUR, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
//return c.getTimeInMillis(); // this won't work for JDK 1.3
return c.getTime().getTime() - 1;
}
示例4: fastTimeCreate
import java.util.Calendar; //導入方法依賴的package包/類
final static Time fastTimeCreate(Calendar cal, int hour, int minute, int second, ExceptionInterceptor exceptionInterceptor) throws SQLException {
if (hour < 0 || hour > 24) {
throw SQLError.createSQLException(
"Illegal hour value '" + hour + "' for java.sql.Time type in value '" + timeFormattedString(hour, minute, second) + ".",
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor);
}
if (minute < 0 || minute > 59) {
throw SQLError.createSQLException(
"Illegal minute value '" + minute + "' for java.sql.Time type in value '" + timeFormattedString(hour, minute, second) + ".",
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor);
}
if (second < 0 || second > 59) {
throw SQLError.createSQLException(
"Illegal minute value '" + second + "' for java.sql.Time type in value '" + timeFormattedString(hour, minute, second) + ".",
SQLError.SQL_STATE_ILLEGAL_ARGUMENT, exceptionInterceptor);
}
synchronized (cal) {
java.util.Date origCalDate = cal.getTime();
try {
cal.clear();
// Set 'date' to epoch of Jan 1, 1970
cal.set(1970, 0, 1, hour, minute, second);
long timeAsMillis = cal.getTimeInMillis();
return new Time(timeAsMillis);
} finally {
cal.setTime(origCalDate);
}
}
}
示例5: unmarshalDate
import java.util.Calendar; //導入方法依賴的package包/類
@Test
public void unmarshalDate() throws Exception {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.clear();
calendar.set(2000, 0, 1); // Month is zero-based
assertEquals(calendar.getTime(), DateIonUnmarshaller.getInstance().unmarshall(context("2000-01-01T")));
}
示例6: getTime
import java.util.Calendar; //導入方法依賴的package包/類
public long getTime(int time) {
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(Calendar.HOUR_OF_DAY, iMinutes[time]/60);
cal.set(Calendar.MINUTE, iMinutes[time]%60);
return cal.getTimeInMillis();
}
示例7: isHoliday
import java.util.Calendar; //導入方法依賴的package包/類
/**
* Checks if the given date is a holiday.
* @param cal date to check
* @return true, if date is a holiday, otherwise false
*/
@Override
public boolean isHoliday(Calendar cal) {
Objects.requireNonNull(cal, "parameter cal must not be null!");
// clear time in given date (cal)
cal.set(java.util.Calendar.HOUR_OF_DAY, 0);
cal.clear(java.util.Calendar.MINUTE);
cal.clear(java.util.Calendar.SECOND);
// create filter for search in calendar
Period period = new Period(new DateTime(cal.getTime()), new Dur(1, 0, 0, 0));
Filter filter = new Filter(new PeriodRule(period));
// get all events for the given date
Collection<VEvent> filteredEvents = filter.filter(calendar.getComponents(Component.VEVENT));
// here is a little workaround: if we have an event for the given date in the holiday calendar
// then the given date must be a holiday. however, ical4j returns an event even for the day
// after the holiday. so we check if the endDate of the event is our date. in that case, we ignore
// the event und return false.
if(filteredEvents.size() == 1) {
VEvent event = filteredEvents.iterator().next();
GregorianCalendar endDateCal = new GregorianCalendar();
endDateCal.setTime(event.getEndDate().getDate());
if(endDateCal.get(Calendar.MONTH) == cal.get(Calendar.MONTH)
&& endDateCal.get(Calendar.DATE) == cal.get(Calendar.DATE)) {
return false;
}
return true;
}
return filteredEvents.size() > 0;
}
示例8: getAutofillValue
import java.util.Calendar; //導入方法依賴的package包/類
@Override
public AutofillValue getAutofillValue() {
Calendar calendar = Calendar.getInstance();
// Set hours, minutes, seconds, and millis to 0 to ensure getAutofillValue() == the value
// set by autofill(). Without this line, the view will not turn yellow when updated.
calendar.clear();
int year = Integer.parseInt(mCcExpYearSpinner.getSelectedItem().toString());
int month = mCcExpMonthSpinner.getSelectedItemPosition();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
long unixTime = calendar.getTimeInMillis();
return AutofillValue.forDate(unixTime);
}
開發者ID:googlesamples,項目名稱:android-AutofillFramework,代碼行數:14,代碼來源:CreditCardExpirationDateCompoundView.java
示例9: calculateReturnDate
import java.util.Calendar; //導入方法依賴的package包/類
/**
*
* @param flight_date
* @param return_days
* @return
*/
protected static final TimestampType calculateReturnDate(TimestampType flight_date, int return_days) {
assert(return_days >= 0);
// Round this to the start of the day
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(flight_date.getTime() + (return_days * SEATSConstants.MICROSECONDS_PER_DAY));
int year = cal.get(Calendar.YEAR);
int month= cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
cal.clear();
cal.set(year, month, day);
return (new TimestampType(cal.getTime()));
}
示例10: compareTime
import java.util.Calendar; //導入方法依賴的package包/類
/**
* 根據單位字段比較兩個時間
*
* @param date
* 時間1
* @param otherDate
* 時間2
* @param withUnit
* 單位字段,從Calendar field取值
* @return 等於返回0值, 大於返回大於0的值 小於返回小於0的值
*/
public static int compareTime(Date date, Date otherDate, int withUnit) {
Calendar dateCal = Calendar.getInstance();
dateCal.setTime(date);
Calendar otherDateCal = Calendar.getInstance();
otherDateCal.setTime(otherDate);
dateCal.clear(Calendar.YEAR);
dateCal.clear(Calendar.MONTH);
dateCal.set(Calendar.DATE, 1);
otherDateCal.clear(Calendar.YEAR);
otherDateCal.clear(Calendar.MONTH);
otherDateCal.set(Calendar.DATE, 1);
switch (withUnit) {
case Calendar.HOUR:
dateCal.clear(Calendar.MINUTE);
otherDateCal.clear(Calendar.MINUTE);
case Calendar.MINUTE:
dateCal.clear(Calendar.SECOND);
otherDateCal.clear(Calendar.SECOND);
case Calendar.SECOND:
dateCal.clear(Calendar.MILLISECOND);
otherDateCal.clear(Calendar.MILLISECOND);
case Calendar.MILLISECOND:
break;
default:
throw new IllegalArgumentException("withUnit 單位字段 " + withUnit + " 不合法!!");
}
return dateCal.compareTo(otherDateCal);
}
示例11: toGeneralizedTimeString
import java.util.Calendar; //導入方法依賴的package包/類
/**
* Returns a string representation of KerberosTime object.
* @return a string representation of this object.
*/
public String toGeneralizedTimeString() {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.clear();
calendar.setTimeInMillis(kerberosTime);
return String.format("%04d%02d%02d%02d%02d%02dZ",
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH) + 1,
calendar.get(Calendar.DAY_OF_MONTH),
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
calendar.get(Calendar.SECOND));
}
示例12: main
import java.util.Calendar; //導入方法依賴的package包/類
/**
* @param args the command line arguments
*/
@PersistenceUnit
public static void main(String[] args) {
System.out.println("Creating entity information...");
EntityManager entityManager = Persistence.createEntityManagerFactory("DataAppLibraryPULocal").createEntityManager();
EntityTransaction et = entityManager.getTransaction();
et.begin();
loadDiscountRate(entityManager);
loadRegion(entityManager);
loadRole(entityManager);
loadTransmission(entityManager);
loadProductType(entityManager);
loadEngine(entityManager);
loadProduct(entityManager);
et.commit();
EntityManager specialEntityManager = new InitialLoadEntityManagerProxy(entityManager);
SalesSimulator simulator = new SalesSimulator(specialEntityManager);
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
cal.clear();
cal.set(year-1, 0, 1, 0, 0, 0); // go back to begining of year, 3 years ago
System.out.println("Creating historical data...");
System.out.println(" This may take 5 to 15min depending on machine speed.");
simulator.run(cal.getTime(), new Date());
entityManager.close();
}
示例13: timetMillisFromEpochSecs
import java.util.Calendar; //導入方法依賴的package包/類
/**
* Get a "time_t" in millis given a number of seconds since
* Dershowitz/Reingold epoch relative to a given timezone.
* @param epochSecs Number of seconds since Dershowitz/Reingold
* epoch, relatve to zone.
* @param zone Timezone against which epochSecs applies
* @return Number of milliseconds since 00:00:00 Jan 1, 1970 GMT
*/
private static long timetMillisFromEpochSecs(long epochSecs,
TimeZone zone) {
DateTimeValue date = timeFromSecsSinceEpoch(epochSecs);
Calendar cal = new GregorianCalendar(zone);
cal.clear(); // clear millis
cal.setTimeZone(zone);
cal.set(date.year(), date.month() - 1, date.day(),
date.hour(), date.minute(), date.second());
return cal.getTimeInMillis();
}
示例14: fastTimestampCreate
import java.util.Calendar; //導入方法依賴的package包/類
final static Timestamp fastTimestampCreate(TimeZone tz, int year, int month, int day, int hour, int minute, int seconds, int secondsPart) {
Calendar cal = (tz == null) ? new GregorianCalendar() : new GregorianCalendar(tz);
cal.clear();
// why-oh-why is this different than java.util.date, in the year part, but it still keeps the silly '0' for the start month????
cal.set(year, month - 1, day, hour, minute, seconds);
long tsAsMillis = cal.getTimeInMillis();
Timestamp ts = new Timestamp(tsAsMillis);
ts.setNanos(secondsPart);
return ts;
}
示例15: testSingleWriterUseHeaders
import java.util.Calendar; //導入方法依賴的package包/類
@Test
public void testSingleWriterUseHeaders()
throws Exception {
String[] colNames = {COL1, COL2};
String PART1_NAME = "country";
String PART2_NAME = "hour";
String[] partNames = {PART1_NAME, PART2_NAME};
List<String> partitionVals = null;
String PART1_VALUE = "%{" + PART1_NAME + "}";
String PART2_VALUE = "%y-%m-%d-%k";
partitionVals = new ArrayList<String>(2);
partitionVals.add(PART1_VALUE);
partitionVals.add(PART2_VALUE);
String tblName = "hourlydata";
TestUtil.dropDB(conf, dbName2);
String dbLocation = dbFolder.newFolder(dbName2).getCanonicalPath() + ".db";
dbLocation = dbLocation.replaceAll("\\\\","/"); // for windows paths
TestUtil.createDbAndTable(driver, dbName2, tblName, partitionVals, colNames,
colTypes, partNames, dbLocation);
int totalRecords = 4;
int batchSize = 2;
int batchCount = totalRecords / batchSize;
Context context = new Context();
context.put("hive.metastore",metaStoreURI);
context.put("hive.database",dbName2);
context.put("hive.table",tblName);
context.put("hive.partition", PART1_VALUE + "," + PART2_VALUE);
context.put("autoCreatePartitions","true");
context.put("useLocalTimeStamp", "false");
context.put("batchSize","" + batchSize);
context.put("serializer", HiveDelimitedTextSerializer.ALIAS);
context.put("serializer.fieldnames", COL1 + ",," + COL2 + ",");
context.put("heartBeatInterval", "0");
Channel channel = startSink(sink, context);
Calendar eventDate = Calendar.getInstance();
List<String> bodies = Lists.newArrayList();
// push events in two batches - two per batch. each batch is diff hour
Transaction txn = channel.getTransaction();
txn.begin();
for (int j = 1; j <= totalRecords; j++) {
Event event = new SimpleEvent();
String body = j + ",blah,This is a log message,other stuff";
event.setBody(body.getBytes());
eventDate.clear();
eventDate.set(2014, 03, 03, j % batchCount, 1); // yy mm dd hh mm
event.getHeaders().put( "timestamp",
String.valueOf(eventDate.getTimeInMillis()) );
event.getHeaders().put( PART1_NAME, "Asia" );
bodies.add(body);
channel.put(event);
}
// execute sink to process the events
txn.commit();
txn.close();
checkRecordCountInTable(0, dbName2, tblName);
for (int i = 0; i < batchCount ; i++) {
sink.process();
}
checkRecordCountInTable(totalRecords, dbName2, tblName);
sink.stop();
// verify counters
SinkCounter counter = sink.getCounter();
Assert.assertEquals(2, counter.getConnectionCreatedCount());
Assert.assertEquals(2, counter.getConnectionClosedCount());
Assert.assertEquals(2, counter.getBatchCompleteCount());
Assert.assertEquals(0, counter.getBatchEmptyCount());
Assert.assertEquals(0, counter.getConnectionFailedCount() );
Assert.assertEquals(4, counter.getEventDrainAttemptCount());
Assert.assertEquals(4, counter.getEventDrainSuccessCount() );
}