當前位置: 首頁>>代碼示例>>Java>>正文


Java Calendar.clone方法代碼示例

本文整理匯總了Java中java.util.Calendar.clone方法的典型用法代碼示例。如果您正苦於以下問題:Java Calendar.clone方法的具體用法?Java Calendar.clone怎麽用?Java Calendar.clone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Calendar的用法示例。


在下文中一共展示了Calendar.clone方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getSoFarWentDays

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * 以日期中的日為實際計算單位,計算兩個時間點實際日的差距 比如 12-1 23:00 和12-2 01:00,相差1天,而不是小於24小時就算做0天
 * 如果(now - st)為正,則表示now在st之後
 *
 * @param st
 * @param now
 * @return
 */
public static int getSoFarWentDays(Calendar st, Calendar now) {

	int sign = st.before(now) ? 1 : -1;
	if (now.before(st)) {
		Calendar tmp = now;
		now = st;
		st = tmp;
	}
	int days = now.get(Calendar.DAY_OF_YEAR) - st.get(Calendar.DAY_OF_YEAR);
	if (st.get(Calendar.YEAR) != now.get(Calendar.YEAR)) {
		Calendar cloneSt = (Calendar) st.clone();
		while (cloneSt.get(Calendar.YEAR) != now.get(Calendar.YEAR)) {
			days += cloneSt.getActualMaximum(Calendar.DAY_OF_YEAR);
			cloneSt.add(Calendar.YEAR, 1);
		}
	}

	return days * sign;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:28,代碼來源:TimeUtils.java

示例2: initTable

import java.util.Calendar; //導入方法依賴的package包/類
public void initTable(CalendarDate d) {
	setModel(new EventsTableModel());
	int fDow = Configuration.get("FIRST_DAY_OF_WEEK").equals("mon")?Calendar.MONDAY:Calendar.SUNDAY;
	Calendar cal = d.getCalendar();
	if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY && fDow == Calendar.MONDAY) cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)-6);
	else 
		cal.set(Calendar.DAY_OF_WEEK, fDow);
	Calendar changeCal = (Calendar)cal.clone();
	for(int i = 0;i<7;i++){
		changeCal.set(Calendar.DAY_OF_YEAR, i+cal.get(Calendar.DAY_OF_YEAR));
		events[i] = new Vector(EventsManager.getEventsForDate(new CalendarDate(changeCal)));
		days[i] = (Calendar)changeCal.clone();
	}
		
    for(int i = 0;i<getColumnModel().getColumnCount();i++){
    	getColumnModel().getColumn(i).setPreferredWidth(100);
        getColumnModel().getColumn(i).setMaxWidth(100);
    }
    clearSelection();
    updateUI();
}
 
開發者ID:ser316asu,項目名稱:SER316-Dresden,代碼行數:22,代碼來源:EventsTableWeekly.java

示例3: start

import java.util.Calendar; //導入方法依賴的package包/類
public static void start(Context ctx) {
    AlarmManager manager = (AlarmManager) ctx.getSystemService("alarm");
    PendingIntent pending = PendingIntent.getBroadcast(ctx, requestCode, new Intent(ctx,
            DailySignReceiver.class), 134217728);
    Helper.showLog(TAG, "DailySignReceiver start");
    Calendar calNow = Calendar.getInstance();
    Calendar calSet = (Calendar) calNow.clone();
    calSet.setTimeInMillis(System.currentTimeMillis());
    calSet.set(11, 12);
    calSet.set(12, 0);
    calSet.set(13, 0);
    calSet.set(14, 0);
    if (calSet.compareTo(calNow) <= 0) {
        calSet.add(5, 1);
    }
    manager.setRepeating(0, calSet.getTimeInMillis(), a.h, pending);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:18,代碼來源:DailySignReceiver.java

示例4: start

import java.util.Calendar; //導入方法依賴的package包/類
public static void start(Context ctx) {
    AlarmManager manager = (AlarmManager) ctx.getSystemService("alarm");
    PendingIntent pending = PendingIntent.getBroadcast(ctx, 152, new Intent(ctx,
            SportRemindReceiver.class), 134217728);
    Helper.showLog(TAG, "SportRemindReceiver start");
    Calendar calNow = Calendar.getInstance();
    Calendar calSet = (Calendar) calNow.clone();
    calSet.setTimeInMillis(System.currentTimeMillis());
    int remindHour = 20;
    int remindMinute = 30;
    if (!TextUtil.isEmpty(OnePreference.getPrefSportRemindTime())) {
        String[] times = OnePreference.getPrefSportRemindTime().split("#");
        if (times.length == 2) {
            remindHour = Integer.parseInt(times[0]);
            remindMinute = Integer.parseInt(times[1]);
        }
    }
    calSet.set(11, remindHour);
    calSet.set(12, remindMinute);
    calSet.set(13, 0);
    calSet.set(14, 0);
    if (calSet.compareTo(calNow) <= 0) {
        calSet.add(5, 1);
    }
    manager.setRepeating(0, calSet.getTimeInMillis(), a.h, pending);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:27,代碼來源:SportRemindReceiver.java

示例5: getSoFarWentHours

import java.util.Calendar; //導入方法依賴的package包/類
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;
	}
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:36,代碼來源:TimeUtils.java

示例6: isAfter

import java.util.Calendar; //導入方法依賴的package包/類
protected boolean isAfter(Calendar now, String time) {
    String[] hourAndMin = StringUtils.split(time, ":");
    if (hourAndMin == null || hourAndMin.length != 2) {
        log.error("error period time format in rule : " + time);
        return isInPeriodWhenErrorFormat();
    }

    int hour;
    int min;
    try {
        hour = Integer.parseInt(hourAndMin[0]);
        min = Integer.parseInt(hourAndMin[1]);
    } catch (NumberFormatException e) {
        log.error("error period time format in rule : " + time, e);
        return isInPeriodWhenErrorFormat();
    }

    if (hour > 24 || min > 60) {
        log.error("error period time format in rule : " + time);
        return isInPeriodWhenErrorFormat();
    }

    Calendar when = (Calendar) now.clone();
    when.set(Calendar.HOUR_OF_DAY, hour);
    when.set(Calendar.MINUTE, min);

    return !now.before(when);
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:29,代碼來源:AbstractRuleMonitor.java

示例7: isLastDayofWeek

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Return if the date is the last Day of the month
 * @param calendar Calendar object in query
 * @param countryName the country name
 * @return true if it is otherwise return false
 */
public static boolean isLastDayofWeek(Calendar calendar, String countryName){
    
    Calendar local =  (Calendar)calendar.clone();
    
    if(local == null)
        return false;

    //If it is Friday
    if(local.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY){
        if (isPublicHoliday(local, countryName)){
            return false;
        }else{
            return true;
        }
    }else{
        if (isPublicHoliday(local,countryName)){
            return false;
        }else{
            while(local.get(Calendar.DAY_OF_WEEK) != Calendar.FRIDAY){
                local.add(Calendar.DAY_OF_WEEK, 1);
                if (!isWeekend(local) && !isPublicHoliday(local, countryName)){
                    return false;
                }
            }
            //Check the last day of the month is the public holiday or not
            if (!isWeekend(local) && !isPublicHoliday(local,countryName)){
                return false;
            } else {
                return true;
            }
        }
    }
}
 
開發者ID:ztan5,項目名稱:TechnicalAnalysisTool,代碼行數:40,代碼來源:DateUtil.java

示例8: isMonthAfter

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * This method compares calendars using month and year
 *
 * @param firstCalendar  First calendar object to compare
 * @param secondCalendar Second calendar object to compare
 * @return Boolean value if second calendar is after the first one
 */
public static boolean isMonthAfter(Calendar firstCalendar, Calendar secondCalendar) {
    if (firstCalendar == null) {
        return false;
    }

    Calendar firstDay = (Calendar) firstCalendar.clone();
    setMidnight(firstDay);
    firstDay.set(Calendar.DAY_OF_MONTH, 1);
    Calendar secondDay = (Calendar) secondCalendar.clone();
    setMidnight(secondDay);
    secondDay.set(Calendar.DAY_OF_MONTH, 1);

    return secondDay.after(firstDay);
}
 
開發者ID:Applandeo,項目名稱:Material-Calendar-View,代碼行數:22,代碼來源:DateUtils.java

示例9: getStartOfWeek

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * @param  dayOfWeek            date in the week you would like to get the start date from
 * @param  weekStartDayIndex    index of the day the weeks starts at. ATTENTION: sunday = 1, monday = 2, ...
 * @return                      date of the first day of week
 */
public static Calendar getStartOfWeek(Calendar dayOfWeek, int weekStartDayIndex) {
    Calendar startDay = (Calendar) dayOfWeek.clone();
    while (startDay.get(Calendar.DAY_OF_WEEK) != weekStartDayIndex) {
        startDay.add(Calendar.DATE, -1);
    }
    startDay.set(Calendar.HOUR_OF_DAY, 0);
    startDay.set(Calendar.MINUTE, 00);
    startDay.set(Calendar.SECOND, 00);
    startDay.set(Calendar.MILLISECOND, 000);
    return startDay;
}
 
開發者ID:ITB15-S4-GroupD,項目名稱:Planchester,代碼行數:17,代碼來源:DateHelper.java

示例10: getSpecTimeCountBetween

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * 得到從time1 到time2 中,specTime所指定的時分秒的時刻,有幾次
 * @param time1
 * @param time2
 * @param specTime
 * @return
 */
public static int getSpecTimeCountBetween(long time1, long time2, long specTime)
{
	Calendar st = Calendar.getInstance();
	st.setTimeInMillis(time1);

	Calendar now = Calendar.getInstance();
	now.setTimeInMillis(time2);

	Calendar spec = Calendar.getInstance();
	spec.setTimeInMillis(specTime);

	if (now.before(st)) {
		Calendar tmp = now;
		now = st;
		st = tmp;
	}

	//第一個時間的年月日和被比較時間的時間部分合成
	Calendar st_spec = mergeDateAndTime(st,spec);

	if(isSameDay(time1, time2))
	{
		if(hasSpecTimeBetween(time1,time2,st_spec.getTimeInMillis()))
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}

	int diffDay = 0;
	Calendar cloneSt = (Calendar) st_spec.clone();
	while(cloneSt.before(now))
	{
		cloneSt.add(Calendar.DATE, 1);
		diffDay++;
	}

	if(st.after(st_spec))
	{
		diffDay--;
	}

	return diffDay;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:55,代碼來源:TimeUtils.java

示例11: onBeforeShowDatePicker

import java.util.Calendar; //導入方法依賴的package包/類
private void onBeforeShowDatePicker(int view_id, Calendar cal) {
    mViewId = view_id;
    mActiveCal = (Calendar) cal.clone();
}
 
開發者ID:nhocga1995s,項目名稱:MyCalendar,代碼行數:5,代碼來源:AddEditWeekLessonDialogFragment.java

示例12: CityBot

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Constructor - CityBot
 * @param startCalendar
 * @param airportCode
 * @param latitude
 * @param longitude
 * @param populationInMillions
 * @param addedYearMonthDay
 * @return new CityBot Object
 * @throws Exception
 */
public CityBot (
  Calendar startCalendar,
  String airportCode,
  double latitude,
  double longitude,
  int populationInMillions,
  String addedYearMonthDay) throws Exception {
  
  super(
    "city_bot",
    PeriodicJob.Type.ASYNC,
    startCalendar,
    new Period(
      1.0,
      TimeUnitType.DAY),
    new CycleTickerBuilder()
      .runFor(new Period(1, TimeUnitType.YEAR) )
      .build() );
  
  this.startCalendar = (Calendar)startCalendar.clone();
  
  this.airportCode = airportCode;
  this.latitude = latitude;
  this.longitude = longitude;
  this.populationInMillions = populationInMillions;
  
  this.addedYearMonthDay = addedYearMonthDay;
  this.addedDate = Calendar.getInstance();
  
  String[] addedDateParts = addedYearMonthDay.split("_");
  
  this.addedDate.set(
    Integer.parseInt(addedDateParts[0] ),
    Integer.parseInt(addedDateParts[1] ),
    Integer.parseInt(addedDateParts[2] ) );
  
  this.currentCalendar = CalendarAndDateOperationsInl.getCurrentCalendar();
  this.yesterdayCalendar = (Calendar)this.currentCalendar.clone();
  this.yesterdayCalendar.add(Calendar.DATE, -1);
  this.lastWeekCalendar = (Calendar)this.currentCalendar.clone();
  this.lastWeekCalendar.add(Calendar.DATE, -6);
  this.startTillYesterdayCalendars =
    CalendarAndDateOperationsInl.getCalendarsFromTo(
      this.startCalendar,
      this.yesterdayCalendar);
  this.lastWeekTillYesterdayCalendars =
    CalendarAndDateOperationsInl.getCalendarsFromTo(
      this.lastWeekCalendar,
      this.yesterdayCalendar);
  this.lastWeekTillTodayCalendars =
    CalendarAndDateOperationsInl.getCalendarsFromTo(
      this.lastWeekCalendar,
      this.currentCalendar);
  this.weekCount =
    CalendarAndDateOperationsInl.getWeekCalendarsRanges(
      this.startCalendar,
      this.currentCalendar).size();
}
 
開發者ID:vangav,項目名稱:vos_instagram_bots,代碼行數:70,代碼來源:CityBot.java

示例13: AddHours

import java.util.Calendar; //導入方法依賴的package包/類
@SimpleFunction(description = "An instant in time some hours after the argument")
public static Calendar AddHours(Calendar instant, int quantity) {
  Calendar newInstant = (Calendar) instant.clone();
  Dates.DateAdd(newInstant, Calendar.HOUR_OF_DAY, quantity);
  return newInstant;
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:7,代碼來源:Clock.java

示例14: AddMinutes

import java.util.Calendar; //導入方法依賴的package包/類
@SimpleFunction(description = "An instant in time some minutes after the argument")
public static Calendar AddMinutes(Calendar instant, int quantity) {
  Calendar newInstant = (Calendar) instant.clone();
  Dates.DateAdd(newInstant, Calendar.MINUTE, quantity);
  return newInstant;
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:7,代碼來源:Clock.java

示例15: timestamp

import java.util.Calendar; //導入方法依賴的package包/類
private Date timestamp ( final Calendar base, final int addSeconds )
{
    final Calendar c = (Calendar)base.clone ();
    c.add ( Calendar.SECOND, addSeconds );
    return c.getTime ();
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:7,代碼來源:QueryBufferTest.java


注:本文中的java.util.Calendar.clone方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。