当前位置: 首页>>代码示例>>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;未经允许,请勿转载。