本文整理了Java中java.util.Calendar.clone()
方法的一些代码示例,展示了Calendar.clone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Calendar.clone()
方法的具体详情如下:
包路径:java.util.Calendar
类名称:Calendar
方法名:clone
[英]Returns a shallow copy of this Calendar with the same properties.
[中]返回具有相同属性的此日历的浅表副本。
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Return the next calendar in the iteration
*
* @return Object calendar for the next date
*/
@Override
public Calendar next() {
if (spot.equals(endFinal)) {
throw new NoSuchElementException();
}
spot.add(Calendar.DATE, 1);
return (Calendar) spot.clone();
}
代码示例来源:origin: stackoverflow.com
Calendar now = Calendar.getInstance();
Calendar tmp = (Calendar) now.clone();
tmp.add(Calendar.HOUR_OF_DAY, 1);
tmp.add(Calendar.MINUTE, 10);
Calendar nowPlus70Minutes = tmp;
tmp = (Calendar) now.clone();
tmp.add(Calendar.MINUTE, -10);
Calendar nowMinus10Minutes = tmp;
代码示例来源:origin: commons-lang/commons-lang
/**
* <p>Formats a <code>Calendar</code> object into the
* supplied <code>StringBuffer</code>.</p>
*
* @param calendar the calendar to format
* @param buf the buffer to format into
* @return the specified string buffer
*/
public StringBuffer format(Calendar calendar, StringBuffer buf) {
if (mTimeZoneForced) {
calendar.getTime(); /// LANG-538
calendar = (Calendar) calendar.clone();
calendar.setTimeZone(mTimeZone);
}
return applyRules(calendar, buf);
}
代码示例来源:origin: stackoverflow.com
Calendar myBirthDate = Calendar.getInstance();
myBirthDate.clear();
myBirthDate.set(1978, 3 - 1, 26);
Calendar now = Calendar.getInstance();
Calendar clone = (Calendar) myBirthDate.clone(); // Otherwise changes are been reflected.
int years = -1;
while (!clone.after(now)) {
clone.add(Calendar.YEAR, 1);
years++;
}
System.out.println(years); // 32
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) {
// set the date
Calendar cal = Calendar.getInstance();
cal.set(2011, 10 - 1, 12);
// "calculate" the start date of the week
Calendar first = (Calendar) cal.clone();
first.add(Calendar.DAY_OF_WEEK,
first.getFirstDayOfWeek() - first.get(Calendar.DAY_OF_WEEK));
// and add six days to the end date
Calendar last = (Calendar) first.clone();
last.add(Calendar.DAY_OF_YEAR, 6);
// print the result
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(df.format(first.getTime()) + " -> " +
df.format(last.getTime()));
}
代码示例来源:origin: quartz-scheduler/quartz
test = (Calendar) test.clone();
test.set(Calendar.MILLISECOND, 0); // don't compare millis.
test.set(Calendar.HOUR_OF_DAY, 0);
test.set(Calendar.MINUTE, 0);
test.set(Calendar.SECOND, 0);
Date testTime = test.getTime();
Date fta = getFireTimeAfter(new Date(test.getTime().getTime() - 1000));
Calendar p = Calendar.getInstance(test.getTimeZone());
p.setTime(fta);
int year = p.get(Calendar.YEAR);
int month = p.get(Calendar.MONTH);
int day = p.get(Calendar.DATE);
代码示例来源:origin: stackoverflow.com
Calendar calendar = Calendar.getInstance();
onTimeSetListener, calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE), is24r);
timePickerDialog.setTitle("Set Alarm Time");
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Calendar calNow = Calendar.getInstance();
Calendar calSet = (Calendar) calNow.clone();
calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
calSet.set(Calendar.MINUTE, minute);
calSet.set(Calendar.SECOND, 0);
calSet.set(Calendar.MILLISECOND, 0);
calSet.add(Calendar.DATE, 1);
+ targetCal.getTime() + "\n" + "***\n");
代码示例来源:origin: wildfly/wildfly
return null;
Calendar nextCal = (Calendar) currentCal.clone();
nextCal.setTimeZone(this.timezone);
Date start = this.scheduleExpression.getStart();
if (start != null && currentCal.getTime().before(start)) {
if (increment) {
nextCal.add(Calendar.SECOND, 1);
nextCal.add(Calendar.MILLISECOND, -nextCal.get(Calendar.MILLISECOND));
代码示例来源:origin: lealone/Lealone
/**
* Convert a date to the specified time zone.
*
* @param x the date to convert
* @param target the calendar with the target timezone
* @return the milliseconds in UTC
*/
public static long convertToLocal(java.util.Date x, Calendar target) {
if (target == null) {
throw DbException.getInvalidValueException("calendar", null);
}
target = (Calendar) target.clone();
Calendar local = Calendar.getInstance();
synchronized (local) {
local.setTime(x);
convertTime(local, target);
}
return target.getTime().getTime();
}
代码示例来源:origin: wdullaer/MaterialDateTimePicker
TimeZone timeZone = mController == null ? TimeZone.getDefault() : mController.getTimeZone();
newCalendar.setTimeZone(timeZone);
return (Calendar) newCalendar.clone();
long lowDistance = Math.abs(calendar.getTimeInMillis() - lower.getTimeInMillis());
if (lowDistance < highDistance) return (Calendar) lower.clone();
else return (Calendar) higher.clone();
Calendar forwardDate = isBeforeMin(calendar) ? getStartDate() : (Calendar) calendar.clone();
Calendar backwardDate = isAfterMax(calendar) ? getEndDate() : (Calendar) calendar.clone();
while (isDisabled(forwardDate) && isDisabled(backwardDate)) {
forwardDate.add(Calendar.DAY_OF_MONTH, 1);
backwardDate.add(Calendar.DAY_OF_MONTH, -1);
if (mMinDate != null) return (Calendar) mMinDate.clone();
Calendar output = Calendar.getInstance(timezone);
output.set(Calendar.YEAR, mMinYear);
output.set(Calendar.MONTH, Calendar.JANUARY);
output.set(Calendar.DAY_OF_MONTH, 1);
return Utils.trimToMidnight(output);
if (mMaxDate != null) return (Calendar) mMaxDate.clone();
Calendar output = Calendar.getInstance(timezone);
output.set(Calendar.YEAR, mMaxYear);
output.set(Calendar.MONTH, Calendar.DECEMBER);
代码示例来源:origin: jwpttcg66/NettyGameServer
public static int getSoFarWentHours(long time1, long time2) {
Calendar st = Calendar.getInstance();
st.setTimeInMillis(time1);
Calendar now = Calendar.getInstance();
now.setTimeInMillis(time2);
if (now.before(st)) {
Calendar tmp = now;
now = st;
st = tmp;
}
st.clear(Calendar.MILLISECOND);
st.clear(Calendar.SECOND);
st.clear(Calendar.MINUTE);
int diffHour = 0;
Calendar cloneSt = (Calendar) st.clone();
while(cloneSt.before(now))
{
cloneSt.add(Calendar.HOUR, 1);
diffHour++;
}
if(diffHour != 0)
{
return diffHour - 1;
}
else
{
return diffHour;
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
end = (Calendar) start.clone();
end.add(Calendar.MONTH, 1);
end.add(Calendar.DATE, -1);
break;
case RANGE_WEEK_RELATIVE:
startCutoff = focus.get(Calendar.DAY_OF_WEEK);
endCutoff = startCutoff - 1;
break;
case RANGE_WEEK_CENTER:
startCutoff = focus.get(Calendar.DAY_OF_WEEK) - 3;
endCutoff = focus.get(Calendar.DAY_OF_WEEK) + 3;
break;
default:
while (start.get(Calendar.DAY_OF_WEEK) != startCutoff) {
start.add(Calendar.DATE, -1);
while (end.get(Calendar.DAY_OF_WEEK) != endCutoff) {
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
public static Date getGTDate(Calendar cal) {
Calendar gtCal = (Calendar)cal.clone();
gtCal.set(Calendar.HOUR_OF_DAY, 0);
gtCal.set(Calendar.MINUTE, 0);
gtCal.set(Calendar.SECOND, 0);
gtCal.set(Calendar.MILLISECOND, 0);
return gtCal.getTime();
}
代码示例来源:origin: org.codehaus.groovy/groovy
@Deprecated
public static int minus(Date self, Date then) {
Calendar a = (Calendar) Calendar.getInstance().clone();
a.setTime(self);
Calendar b = (Calendar) Calendar.getInstance().clone();
b.setTime(then);
return minus(a, b);
}
代码示例来源:origin: wdullaer/MaterialDateTimePicker
@Override
public @NonNull Calendar getStartDate() {
if (!selectableDays.isEmpty()) return (Calendar) selectableDays.first().clone();
if (mMinDate != null) return (Calendar) mMinDate.clone();
TimeZone timeZone = mController == null ? TimeZone.getDefault() : mController.getTimeZone();
Calendar output = Calendar.getInstance(timeZone);
output.set(Calendar.YEAR, mMinYear);
output.set(Calendar.DAY_OF_MONTH, 1);
output.set(Calendar.MONTH, Calendar.JANUARY);
return output;
}
代码示例来源:origin: stackoverflow.com
Calendar cal3 = Calendar.getInstance();
cal3.setTime(sDate);
Calendar cal4 = Calendar.getInstance();
cal4.setTime(eDate);
return daysBetween(cal3, cal4);
Calendar date = (Calendar) startDate.clone();
long daysBetween = 0;
while (date.before(endDate)) {
date.add(Calendar.DAY_OF_MONTH, 1);
daysBetween++;
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
.getTime());
cal.setTimeInMillis(sysRead.getCurrentTime());
} else
cal = (Calendar) now.clone();
cal.add(Calendar.DATE, -1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
cal.add(Calendar.YEAR, -number);
else if ("month".equals(parts[i + 1]) //$NON-NLS-1$
|| "months".equals(parts[i + 1])) //$NON-NLS-1$
cal.add(Calendar.MONTH, -number);
else if ("week".equals(parts[i + 1]) //$NON-NLS-1$
|| "weeks".equals(parts[i + 1])) //$NON-NLS-1$
return null;
return cal.getTime();
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
/**
* Method getWeekNumber
*
* @return long
*/
protected static long getWeekNumber(Calendar cal) {
Calendar tempCal = (Calendar)cal.clone();
// Set to midnight, GMT
tempCal.set(Calendar.MILLISECOND, 0);
tempCal.set(Calendar.SECOND, 0);
tempCal.set(Calendar.MINUTE, 0);
tempCal.set(Calendar.HOUR_OF_DAY, 0);
// Roll back to the first day of the week
int delta =
tempCal.getFirstDayOfWeek() - tempCal.get(Calendar.DAY_OF_WEEK);
if (delta > 0) {
delta -= 7;
}
// tempCal now points to the first instant of this week.
// Calculate the "week epoch" -- the weekstart day closest to January 1,
// 1970 (which was a Thursday)
long weekEpoch =
(tempCal.getFirstDayOfWeek() - Calendar.THURSDAY) * 24L * 60 * 60 *
1000;
return (tempCal.getTime().getTime() - weekEpoch) /
(7 * 24 * 60 * 60 * 1000);
}
代码示例来源:origin: geotools/geotools
public void testCalendarToTime() throws Exception {
Calendar calendar = Calendar.getInstance(/*TimeZone.getTimeZone("GMT")*/ );
calendar.clear();
calendar.set(Calendar.HOUR_OF_DAY, 17);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 1);
assertNotNull(factory.createConverter(Calendar.class, Time.class, null));
Time time =
(Time)
factory.createConverter(Calendar.class, Time.class, null)
.convert(calendar, Time.class);
assertNotNull(time);
// need to remove the date part
Calendar cal = (Calendar) calendar.clone();
cal.set(Calendar.YEAR, 0);
cal.set(Calendar.MONTH, 0);
cal.set(Calendar.DAY_OF_MONTH, 0);
assertEquals(cal.getTimeInMillis(), time.getTime());
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
Calendar myCurrent = (Calendar)current.clone();
myCurrent.setMinimalDaysInFirstWeek(4);
myCurrent.setFirstDayOfWeek(dtStart.getFirstDayOfWeek());
myCurrent.set(Calendar.SECOND, 0);
myCurrent.set(Calendar.MILLISECOND, 0);
if (myCurrent.getTime().getTime() < dtStart.getTime().getTime()) {
while ((candidate.getTime().getTime() + duration.getInterval()) >
myCurrent.getTime().getTime()) {
candidate.add(Calendar.SECOND, -1);
内容来源于网络,如有侵权,请联系作者删除!