本文整理匯總了Java中java.util.Calendar.getTime方法的典型用法代碼示例。如果您正苦於以下問題:Java Calendar.getTime方法的具體用法?Java Calendar.getTime怎麽用?Java Calendar.getTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Calendar
的用法示例。
在下文中一共展示了Calendar.getTime方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onDateSet
import java.util.Calendar; //導入方法依賴的package包/類
@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();
}
示例2: setupTinaFeyAndSarahPalin
import java.util.Calendar; //導入方法依賴的package包/類
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;
}
示例3: test6
import java.util.Calendar; //導入方法依賴的package包/類
/**
* 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()
);
}
示例4: lookupUserData
import java.util.Calendar; //導入方法依賴的package包/類
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);
}
}
示例5: apply
import java.util.Calendar; //導入方法依賴的package包/類
/**
* {@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));
}
}
示例6: 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);
}
}
}
示例7: addDays
import java.util.Calendar; //導入方法依賴的package包/類
private static Date addDays(Date date, int dayCount) {
Calendar calendar = getCalendar();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, dayCount);
return calendar.getTime();
}
示例8: convertHourMinute2Date
import java.util.Calendar; //導入方法依賴的package包/類
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();
}
示例9: getBeforeDate
import java.util.Calendar; //導入方法依賴的package包/類
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();
}
示例10: main
import java.util.Calendar; //導入方法依賴的package包/類
@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�࣬����Ҫת��
}
示例11: fromLocalDateTime
import java.util.Calendar; //導入方法依賴的package包/類
/**
* 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;
}
示例12: toType
import java.util.Calendar; //導入方法依賴的package包/類
@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();
}
示例13: doBlackMagic
import java.util.Calendar; //導入方法依賴的package包/類
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);
}
}
示例14: findTodayTasks
import java.util.Calendar; //導入方法依賴的package包/類
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);
}
示例15: getTomorrowDate
import java.util.Calendar; //導入方法依賴的package包/類
public static Date getTomorrowDate(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, 1);
return cal.getTime();
}