当前位置: 首页>>代码示例>>Java>>正文


Java Calendar.clear方法代码示例

本文整理汇总了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);

    }
 
开发者ID:Onelio,项目名称:ConnectU,代码行数:24,代码来源:UpdaterHelper.java

示例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());
}
 
开发者ID:bibryam,项目名称:rotabuilder,代码行数:19,代码来源:ShiftDate.java

示例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;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:25,代码来源:Week.java

示例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);
        }
    }
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:36,代码来源:TimeUtil.java

示例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")));
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:8,代码来源:SimpleTypeIonUnmarshallersTest.java

示例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();
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:9,代码来源:TimePatternModel.java

示例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;
}
 
开发者ID:ste-bo,项目名称:workdays,代码行数:42,代码来源:FileHolidayProvider.java

示例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()));
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:21,代码来源:ReturnFlight.java

示例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);
}
 
开发者ID:mumucommon,项目名称:mumu-core,代码行数:41,代码来源:DateUtils.java

示例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));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:KerberosTime.java

示例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();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:32,代码来源:DataAppLoader.java

示例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();
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:19,代码来源:TimeUtils.java

示例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;
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:15,代码来源:TimeUtil.java

示例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() );

}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:80,代码来源:TestHiveSink.java


注:本文中的java.util.Calendar.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。