Java Code Examples for java.util.Calendar.getTime()

The following are Jave code examples for showing how to use getTime() of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: TVGuide   File: MainActivity.java   View Source Code Vote up 6 votes
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear,
                      int dayOfMonth) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MONTH, monthOfYear);
    calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    Date date = calendar.getTime();
    preferencesHelper.setCurProgramsDate(getString(R.string.pref_program_date_key), date.getTime());
    getContentResolver().notifyChange(TvContract.ChannelEntry.CONTENT_URI, null);
    updateChannelView();
}
 
Example 2
Project: grooves   File: BootStrap.java   View Source Code Vote up 6 votes
private Patient setupTinaFeyAndSarahPalin() {
    Patient patient = save(new Patient("47"));
    Patient patient2 = save(new Patient("48"));

    on(patient, it -> {
        it.apply(new PatientCreated("Tina Fey"));
        it.apply(new ProcedurePerformed(ANNUAL_PHYSICAL_NAME,
                new BigDecimal(ANNUAL_PHYSICAL_COST)));
        it.apply(new ProcedurePerformed(GLUCOSE_TEST_NAME, new BigDecimal(GLUCOSE_TEST_COST)));

        it.snapshotWith(patientAccountQuery);
        it.snapshotWith(patientHealthQuery);
    });

    on(patient2, it -> {
        final String name = "Sarah Palin";
        it.apply(new PatientCreated(name));
        it.apply(new PaymentMade(new BigDecimal("100.25")));

        it.snapshotWith(patientAccountQuery);
        it.snapshotWith(patientHealthQuery);
    });

    final Calendar calendar = Calendar.getInstance();
    calendar.setTime(currDate);
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    currDate = calendar.getTime();
    final PatientDeprecatedBy mergeEvent = merge(patient, patient2);

    on(patient, it -> it.apply(new PatientEventReverted(mergeEvent.getId())));
    on(patient2, it -> it.apply(new PatientEventReverted(mergeEvent.getConverse().getId())));

    return patient;
}
 
Example 3
Project: parabuild-ci   File: SegmentedTimelineTests2.java   View Source Code Vote up 6 votes
/**
 * Test 6 checks that 9am on Sunday 28 March 2004 converts to the timeline 
 * value and back again correctly.  Note that Saturday and Sunday are 
 * excluded from the timeline, so we expect the value to map to 9am on 
 * Monday 29 March 2004. This is during daylight saving.
 */
public void test6() {
    Calendar cal = Calendar.getInstance(Locale.UK);
    cal.set(Calendar.YEAR, 2004);
    cal.set(Calendar.MONTH, Calendar.MARCH);
    cal.set(Calendar.DAY_OF_MONTH, 28);
    cal.set(Calendar.HOUR_OF_DAY, 9);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Date date = cal.getTime();
    SegmentedTimeline timeline = getTimeline();      

    long value = timeline.toTimelineValue(date);   
    long ms = timeline.toMillisecond(value);
    Calendar cal2 = Calendar.getInstance(Locale.UK);
    cal2.setTime(new Date(ms));
    Date reverted = cal2.getTime();
  
    Calendar expectedReverted = Calendar.getInstance(Locale.UK);
    expectedReverted.set(Calendar.YEAR, 2004);
    expectedReverted.set(Calendar.MONTH, Calendar.MARCH);
    expectedReverted.set(Calendar.DAY_OF_MONTH, 29);
    expectedReverted.set(Calendar.HOUR_OF_DAY, 9);
    expectedReverted.set(Calendar.MINUTE, 0);
    expectedReverted.set(Calendar.SECOND, 0);
    expectedReverted.set(Calendar.MILLISECOND, 0);
  
    assertTrue(
        "test6", value == (900000 * 34 * 2) 
        && expectedReverted.getTime().getTime() == reverted.getTime()
    );
}
 
Example 4
Project: quorrabot   File: UsernameCache.java   View Source Code Vote up 6 votes
private void lookupUserData(String username) {
    try {
        JSONObject user = TwitchAPIv3.instance().GetUser(username);

        if (user.getBoolean("_success")) {
            if (user.getInt("_http") == 200) {
                if (user.getJSONArray("users").length() > 0) {
                    String displayName = user.getJSONArray("users").getJSONObject(0).getString("display_name").replaceAll("\\\\s", " ");
                    String userID = user.getJSONArray("users").getJSONObject(0).getString("_id");
                    cache.put(username, new UserData(displayName, userID));
                }
            } else {
                com.gmt2001.Console.debug.println("UsernameCache.updateCache: Failed to get username [" + username + "] http error [" + user.getInt("_http") + "]");
            }
        } else {
            if (user.getString("_exception").equalsIgnoreCase("SocketTimeoutException") || user.getString("_exception").equalsIgnoreCase("IOException")) {
                Calendar c = Calendar.getInstance();

                if (lastFail.after(new Date())) {
                    numfail++;
                } else {
                    numfail = 1;
                }

                c.add(Calendar.MINUTE, 1);

                lastFail = c.getTime();

                if (numfail >= 5) {
                    timeoutExpire = c.getTime();
                }
            }
        }
    } catch (Exception e) {
        com.gmt2001.Console.err.printStackTrace(e);
    }
}
 
Example 5
Project: cas-server-4.2.1   File: ThresholdExpiredCRLRevocationPolicy.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 * The CRL next update time is compared against the current time with the threshold
 * applied and rejected if and only if the next update time is in the past.
 *
 * @param crl CRL instance to evaluate.
 *
 * @throws GeneralSecurityException On expired CRL data. Check the exception type for exact details
 *
 * @see org.jasig.cas.adaptors.x509.authentication.handler.support.RevocationPolicy#apply(java.lang.Object)
 */
@Override
public void apply(final X509CRL crl) throws GeneralSecurityException {
    final Calendar cutoff = Calendar.getInstance();
    if (CertUtils.isExpired(crl, cutoff.getTime())) {
        cutoff.add(Calendar.SECOND, -this.threshold);
        if (CertUtils.isExpired(crl, cutoff.getTime())) {
            throw new ExpiredCRLException(crl.toString(), cutoff.getTime(), this.threshold);
        }
        logger.info(String.format("CRL expired on %s but is within threshold period, %s seconds.",
                    crl.getNextUpdate(), this.threshold));
    }
}
 
Example 6
Project: OpenVertretung   File: TimeUtil.java   View Source Code Vote up 6 votes
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);
        }
    }
}
 
Example 7
Project: date-helper   File: FeiertageHelper.java   View Source Code Vote up 6 votes
private static Date addDays(Date date, int dayCount) {

		Calendar calendar = getCalendar();
		calendar.setTime(date);
		calendar.add(Calendar.DAY_OF_MONTH, dayCount);
		return calendar.getTime();
	}
 
Example 8
Project: fitnotifications   File: Func.java   View Source Code Vote up 6 votes
public static Date convertHourMinute2Date(int hour, int minute) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, 0);

    return cal.getTime();
}
 
Example 9
Project: uavstack   File: DateTimeHelper.java   View Source Code Vote up 6 votes
public static Date getBeforeDate(String range) {

        Calendar today = Calendar.getInstance();
        if ("week".equalsIgnoreCase(range))
            today.add(Calendar.WEEK_OF_MONTH, -1);
        else if ("month".equalsIgnoreCase(range))
            today.add(Calendar.MONTH, -1);
        else
            today.clear();
        return today.getTime();
    }
 
Example 10
Project: javaPractise   File: second.java   View Source Code Vote up 6 votes
@SuppressWarnings("static-access")
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Calendar calendar = Calendar.getInstance();
	calendar.add(calendar.DATE, 100); 	// �������ϼ���100��
	Date date=calendar.getTime();		//ת��ΪDate���Ͷ���
	DateFormat fullFormat=DateFormat.getDateInstance(DateFormat.FULL);//FULL��ʽ��DateFormat����
		
	System.out.println(fullFormat.format(date));//DateFormat����ֻ��������Date�࣬����Ҫת��
}
 
Example 11
Project: holon-core   File: ConversionUtils.java   View Source Code Vote up 6 votes
/**
 * Convert a {@link LocalDateTime} value into a {@link Date}, using default calendar.
 * @param dateTime Date/time to convert (may be null)
 * @return Converted {@link Date}, or <code>null</code> if given date was <code>null</code>
 */
public static Date fromLocalDateTime(LocalDateTime dateTime) {
	if (dateTime != null) {
		Calendar c = Calendar.getInstance();
		c.set(Calendar.YEAR, dateTime.getYear());
		c.set(Calendar.MONTH, dateTime.getMonthValue() - 1);
		c.set(Calendar.DAY_OF_MONTH, dateTime.getDayOfMonth());
		c.set(Calendar.HOUR_OF_DAY, dateTime.getHour());
		c.set(Calendar.MINUTE, dateTime.getMinute());
		c.set(Calendar.SECOND, dateTime.getSecond());
		c.set(Calendar.MILLISECOND, (int) TimeUnit.NANOSECONDS.toMillis(dateTime.getNano()));
		return c.getTime();
	}
	return null;
}
 
Example 12
Project: kafka-0.11.0.0-src-with-comment   File: TimestampConverter.java   View Source Code Vote up 6 votes
@Override
public Date toType(Config config, Date orig) {
    Calendar origCalendar = Calendar.getInstance(UTC);
    origCalendar.setTime(orig);
    Calendar result = Calendar.getInstance(UTC);
    result.setTimeInMillis(0L);
    result.set(Calendar.HOUR_OF_DAY, origCalendar.get(Calendar.HOUR_OF_DAY));
    result.set(Calendar.MINUTE, origCalendar.get(Calendar.MINUTE));
    result.set(Calendar.SECOND, origCalendar.get(Calendar.SECOND));
    result.set(Calendar.MILLISECOND, origCalendar.get(Calendar.MILLISECOND));
    return result.getTime();
}
 
Example 13
Project: marathonv5   File: InitialLoadEntityManagerProxy.java   View Source Code Vote up 6 votes
private void doBlackMagic(SalesOrderLine sol){
    SalesOrder so = sol.getOrderId();
    Date date = null;

    //all we care about is the day the sale happened
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(so.getDate().getTime());
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE,0);
    cal.set(Calendar.SECOND,0);
    cal.set(Calendar.MILLISECOND,0);
    
    date = cal.getTime();
    
    if (!dailySalesCounter.containsKey(date)){
        dailySalesCounter.put(date, new HashMap<Product, HashMap<String, HashMap<Region, Integer>>>());
    }
    if (!dailySalesCounter.get(date).containsKey(sol.getProductId())){
        dailySalesCounter.get(date).put(sol.getProductId(), new HashMap<String, HashMap<Region, Integer>>());
    }
    if (!dailySalesCounter.get(date).get(sol.getProductId()).containsKey(so.getCustomerId().getAddressId().getStateProvCd())){
        dailySalesCounter.get(date).get(sol.getProductId()).put(so.getCustomerId().getAddressId().getStateProvCd(), new HashMap<Region,Integer>());
    }
    if (!dailySalesCounter.get(date).get(sol.getProductId()).get(so.getCustomerId().getAddressId().getStateProvCd()).containsKey(so.getRegionId())){
        dailySalesCounter.get(date).get(sol.getProductId()).get(so.getCustomerId().getAddressId().getStateProvCd()).put(so.getRegionId(), sol.getQuantity());
    }
    else{
        Integer quantity = dailySalesCounter.get(date).get(sol.getProductId()).get(so.getCustomerId().getAddressId().getStateProvCd()).put(so.getRegionId(), sol.getQuantity());
        quantity = quantity + sol.getQuantity();
        dailySalesCounter.get(date).get(sol.getProductId()).get(so.getCustomerId().getAddressId().getStateProvCd()).put(so.getRegionId(), quantity);
    }
   
    

}
 
Example 14
Project: lemon   File: PimTaskController.java   View Source Code Vote up 6 votes
public List<PimTask> findTodayTasks(String userId) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    Date startTime = calendar.getTime();
    calendar.add(Calendar.DATE, 1);

    Date endTime = calendar.getTime();
    String hql = "from PimTask where userId=? and startTime between ? and ? order by priority";

    return pimTaskManager.find(hql, userId, startTime, endTime);
}
 
Example 15
Project: springboot-shiro-cas-mybatis   File: ThresholdExpiredCRLRevocationPolicy.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 * The CRL next update time is compared against the current time with the threshold
 * applied and rejected if and only if the next update time is in the past.
 *
 * @param crl CRL instance to evaluate.
 *
 * @throws GeneralSecurityException On expired CRL data. Check the exception type for exact details
 *
 * @see org.jasig.cas.adaptors.x509.authentication.handler.support.RevocationPolicy#apply(java.lang.Object)
 */
@Override
public void apply(final X509CRL crl) throws GeneralSecurityException {
    final Calendar cutoff = Calendar.getInstance();
    if (CertUtils.isExpired(crl, cutoff.getTime())) {
        cutoff.add(Calendar.SECOND, -this.threshold);
        if (CertUtils.isExpired(crl, cutoff.getTime())) {
            throw new ExpiredCRLException(crl.toString(), cutoff.getTime(), this.threshold);
        }
        logger.info(String.format("CRL expired on %s but is within threshold period, %s seconds.",
                    crl.getNextUpdate(), this.threshold));
    }
}
 
Example 16
Project: careconnect-reference-implementation   File: DateHelper.java   View Source Code Vote up 5 votes
public static Date getTomorrowDate(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.DATE, 1);
    return cal.getTime();
}
 
Example 17
Project: logistimo-web-service   File: LocalDateUtil.java   View Source Code Vote up 5 votes
public static Date getOffsetDate(Date d, int amount, int type) {
  Calendar cal = GregorianCalendar.getInstance();
  cal.setTime(d);
  cal.add(type, amount);
  return cal.getTime();
}
 
Example 18
Project: plumdo-stock   File: DateUtils.java   View Source Code Vote up 5 votes
public static Date newDateByDay(Date d, int day) {
	Calendar now = Calendar.getInstance();
	now.setTime(d);
	now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
	return now.getTime();
}
 
Example 19
Project: LucaHome-AndroidApplication   File: CalendarEntryDto.java   View Source Code Vote up 5 votes
public boolean BeginIsAfterNow() {
    Calendar calendar = Calendar.getInstance();
    Date now = calendar.getTime();
    return _begin.after(now);
}
 
Example 20
Project: 3way_laboratorios   File: UtilData.java   View Source Code Vote up 3 votes
public static Date getDate(Calendar data) {

		return data.getTime();
	}