当前位置: 首页>>代码示例>>Java>>正文


Java GregorianCalendar.clone方法代码示例

本文整理汇总了Java中java.util.GregorianCalendar.clone方法的典型用法代码示例。如果您正苦于以下问题:Java GregorianCalendar.clone方法的具体用法?Java GregorianCalendar.clone怎么用?Java GregorianCalendar.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.GregorianCalendar的用法示例。


在下文中一共展示了GregorianCalendar.clone方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSecondInDay

import java.util.GregorianCalendar; //导入方法依赖的package包/类
private long getSecondInDay(GregorianCalendar c){
	long millis=c.getTimeInMillis();
	GregorianCalendar ctemp=(GregorianCalendar) c.clone();
	ctemp.set(GregorianCalendar.HOUR_OF_DAY, 0);
	ctemp.set(GregorianCalendar.MINUTE, 0);
	ctemp.set(GregorianCalendar.SECOND, 0);
	ctemp.set(GregorianCalendar.MILLISECOND, 0);
	long passed = (millis - ctemp.getTimeInMillis())/1000;
	
	return passed;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:12,代码来源:S1Metadata.java

示例2: setAlarm

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void setAlarm() {

        // UPDATE: 2017/8/24 更新 时间段自定义
        current = Calendar.getInstance();
        nightThemeStart = new GregorianCalendar(
                current.get(Calendar.YEAR),
                current.get(Calendar.MONTH),
                current.get(Calendar.DAY_OF_MONTH),
                22, 30); // 22:30 切换到夜间模式

        nightThemeEnd = (Calendar) nightThemeStart.clone();
        nightThemeEnd.add(Calendar.DAY_OF_MONTH, 1); // 后一天
        nightThemeEnd.set(Calendar.HOUR_OF_DAY, 7); // 07:00 切换到白天模式
        nightThemeEnd.set(Calendar.MINUTE, 0);

        checkTheme();
        isSet = true;

        Intent intentS = new Intent();
        Intent intentE = new Intent();

        intentS.setAction(BroadcastManager.FILTER_APP_THEME_CHANGE_AUTOMATIC);
        intentS.putExtra(BroadcastManager.APP_THEME_CHANGE_AUTOMATIC_TOKEN,
                BroadcastManager.APP_THEME_CHANGE_AUTOMATIC_DARK);

        intentE.setAction(BroadcastManager.FILTER_APP_THEME_CHANGE_AUTOMATIC);
        intentE.putExtra(BroadcastManager.APP_THEME_CHANGE_AUTOMATIC_TOKEN,
                BroadcastManager.APP_THEME_CHANGE_AUTOMATIC_WHITE);

        piS = PendingIntent.getBroadcast(context, 0, intentS, 0);
        piE = PendingIntent.getBroadcast(context, 1, intentE, 0);

        alarmManager.set(AlarmManager.RTC_WAKEUP, nightThemeStart.getTimeInMillis(), piS);
        alarmManager.set(AlarmManager.RTC_WAKEUP, nightThemeEnd.getTimeInMillis(), piE);

    }
 
开发者ID:DuanJiaNing,项目名称:Musicoco,代码行数:37,代码来源:AutoSwitchThemeController.java

示例3: main

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static void main(String[] args)
{
    GregorianCalendar cal1 = new GregorianCalendar() ;
    GregorianCalendar cal2 = (GregorianCalendar) cal1.clone() ;

    printdate(cal1, "cal1: ") ;
    printdate(cal2, "cal2 - cloned(): ") ;
    cal1.add(DAY_OF_MONTH, 1) ;
    printdate(cal1, "cal1 after adding 1 day: ") ;
    printdate(cal2, "cal2 should be unmodified: ") ;
    if (cal1.get(DAY_OF_MONTH) == cal2.get(DAY_OF_MONTH)) {
        throw new RuntimeException("cloned GregorianCalendar modified");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:bug4028518.java

示例4: Test4136399

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * Calendar and GregorianCalendar hashCode() methods need improvement.
 * Calendar needs a good implementation that subclasses can override,
 * and GregorianCalendar should use that implementation.
 */
public void Test4136399() {
    /* Note: This test is actually more strict than it has to be.
    * Technically, there is no requirement that unequal objects have
    * unequal hashes.  We only require equal objects to have equal hashes.
    * It is desirable for unequal objects to have distributed hashes, but
    * there is no hard requirement here.
    *
    * In this test we make assumptions about certain attributes of calendar
    * objects getting represented in the hash, which need not always be the
    * case (although it does work currently with the given test). */
    Calendar a = Calendar.getInstance();
    Calendar b = (Calendar) a.clone();
    if (a.hashCode() != b.hashCode()) {
        errln("Calendar hash code unequal for cloned objects");
    }

    b.setMinimalDaysInFirstWeek(7 - a.getMinimalDaysInFirstWeek());
    if (a.hashCode() == b.hashCode()) {
        errln("Calendar hash code ignores minimal days in first week");
    }
    b.setMinimalDaysInFirstWeek(a.getMinimalDaysInFirstWeek());

    b.setFirstDayOfWeek((a.getFirstDayOfWeek() % 7) + 1); // Next day
    if (a.hashCode() == b.hashCode()) {
        errln("Calendar hash code ignores first day of week");
    }
    b.setFirstDayOfWeek(a.getFirstDayOfWeek());

    b.setLenient(!a.isLenient());
    if (a.hashCode() == b.hashCode()) {
        errln("Calendar hash code ignores lenient setting");
    }
    b.setLenient(a.isLenient());

    // Assume getTimeZone() returns a reference, not a clone
    // of a reference -- this is true as of this writing
    b.getTimeZone().setRawOffset(a.getTimeZone().getRawOffset() + 60 * 60 * 1000);
    if (a.hashCode() == b.hashCode()) {
        errln("Calendar hash code ignores zone");
    }
    b.getTimeZone().setRawOffset(a.getTimeZone().getRawOffset());

    GregorianCalendar c = new GregorianCalendar();
    GregorianCalendar d = (GregorianCalendar) c.clone();
    if (c.hashCode() != d.hashCode()) {
        errln("GregorianCalendar hash code unequal for clones objects");
    }
    Date cutover = c.getGregorianChange();
    d.setGregorianChange(new Date(cutover.getTime() + 24 * 60 * 60 * 1000));
    if (c.hashCode() == d.hashCode()) {
        errln("GregorianCalendar hash code ignores cutover");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:59,代码来源:CalendarRegression.java

示例5: Test4141665

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * GregorianCalendar.equals() ignores cutover date
 */
public void Test4141665() {
    GregorianCalendar cal = new GregorianCalendar();
    GregorianCalendar cal2 = (GregorianCalendar) cal.clone();
    Date cut = cal.getGregorianChange();
    Date cut2 = new Date(cut.getTime() + 100 * 24 * 60 * 60 * 1000L); // 100 days later
    if (!cal.equals(cal2)) {
        errln("Cloned GregorianCalendars not equal");
    }
    cal2.setGregorianChange(cut2);
    if (cal.equals(cal2)) {
        errln("GregorianCalendar.equals() ignores cutover");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:CalendarRegression.java

示例6: BackportAppointment

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public BackportAppointment(GregorianCalendar startDate, GregorianCalendar endDate, String title, String persons, String resources) {
    super(title, persons, resources);
    this.start = (GregorianCalendar) startDate.clone();
    this.end = (GregorianCalendar) endDate.clone();
}
 
开发者ID:dhbw-timetable,项目名称:rapla-parser,代码行数:6,代码来源:BackportAppointment.java

示例7: completeDate

import java.util.GregorianCalendar; //导入方法依赖的package包/类
private String completeDate(GregorianCalendar gc, boolean bLongInfo)
{
	GregorianCalendar calendar = (GregorianCalendar)gc.clone();
	
	String csDate = "00000000";
	String csDayOfWeek = "0";
	String csDaysInMonth = "00";
   	String csDayOfYear = "000";
   	String csDaysToEndYear = "000";
   	String csDaysInYear = "000";
   	String csWeekOfYear = "00";
   	String csDayEaster = "000";
   	String csFlagHoliday = " ";
   	String csLeapYear = "0";
   	
   	calendar.setFirstDayOfWeek(GregorianCalendar.MONDAY);
   	calendar.setMinimalDaysInFirstWeek(4);
   	
   	Format formatter = new SimpleDateFormat("yyyyMMdd");
   	csDate = formatter.format(calendar.getTime());
	
   	int dayOfWeek = calendar.get(GregorianCalendar.DAY_OF_WEEK);
	if (dayOfWeek == 1) 
	{
		csDayOfWeek = "7";
	} 
	else 
	{
		csDayOfWeek = String.valueOf(dayOfWeek - 1) ;
	}
	
	csDaysInMonth = String.valueOf(calendar.getActualMaximum(GregorianCalendar.DAY_OF_MONTH));
	
	csWeekOfYear = StringUtil.leftPad(String.valueOf(calendar.get(GregorianCalendar.WEEK_OF_YEAR)), 2, '0');
	
	int dayOfYear = calendar.get(GregorianCalendar.DAY_OF_YEAR);
	calendar.set(GregorianCalendar.MONTH, 11);
	calendar.set(GregorianCalendar.DAY_OF_MONTH, 31);		
	int daysInYear = calendar.get(GregorianCalendar.DAY_OF_YEAR);		
	csDayOfYear = StringUtil.leftPad(String.valueOf(dayOfYear), 3, '0');
	csDaysToEndYear = StringUtil.leftPad(String.valueOf(daysInYear - dayOfYear), 3, '0');
	csDaysInYear = StringUtil.leftPad(String.valueOf(daysInYear), 3, '0');
	
	GregorianCalendar easterCalendar = findDateEaster(calendar.get(GregorianCalendar.YEAR));
	easterCalendar.set(GregorianCalendar.HOUR, 0);
	csDayEaster = StringUtil.leftPad(String.valueOf(easterCalendar.get(GregorianCalendar.DAY_OF_YEAR)), 3, '0');
	
	//int diffEasterDays = elapsedTime(easterCalendar, calendar, GregorianCalendar.DATE);
	long diffMillis = gc.getTimeInMillis() - easterCalendar.getTimeInMillis();
	long diffEasterDays = diffMillis/(24*60*60*1000);
	
	if (csDate.substring(4).equals("0101") ||
		csDate.substring(4).equals("0102") ||
		csDate.substring(4).equals("0801") ||
		csDate.substring(4).equals("1225") ||
		csDate.substring(4).equals("1226") ||
		csDayEaster.equals(csDayOfYear) ||
		diffEasterDays == 1 ||   // lundi de P�ques
		diffEasterDays == 39 ||  // Ascension
		diffEasterDays == 50)    // Pentec�te
	{
		csFlagHoliday = "F";
	}
	
	if (calendar.isLeapYear(calendar.get(GregorianCalendar.YEAR)))
	{
		csLeapYear = "9";
	}
	
	if (bLongInfo)
	{
		return csDate + csDayOfWeek + csDaysInMonth + csDayOfYear + csDaysToEndYear + csDaysInYear + csWeekOfYear + csDayEaster + csFlagHoliday;
	}
	else
	{
		String csTarif = csDayOfWeek;
		if (csFlagHoliday.equals("F"))
			csTarif = "7";
		return csDate.substring(2) + csDayOfYear + csLeapYear + csTarif  + csDayOfWeek + csWeekOfYear;
	}
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:82,代码来源:NacaToolBox.java

示例8: getConsecutiveMonth

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static String getConsecutiveMonth(GregorianCalendar date, int monthNr) {
	GregorianCalendar gClone = (GregorianCalendar)date.clone();
	gClone.add(GregorianCalendar.DAY_OF_MONTH, 28*monthNr);
	return DateGenerator.formatDate(gClone);
}
 
开发者ID:SmartDataAnalytics,项目名称:Embeddable-BSBM,代码行数:6,代码来源:ParameterGenerator.java

示例9: getRandomDate

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static GregorianCalendar getRandomDate(GregorianCalendar dateMin, ValueGenerator valueGen, int days) {
	Integer dayOffset = valueGen.randomInt(0, days);
	GregorianCalendar gClone = (GregorianCalendar)dateMin.clone();
	gClone.add(GregorianCalendar.DAY_OF_MONTH, dayOffset);
	return gClone;
}
 
开发者ID:SmartDataAnalytics,项目名称:Embeddable-BSBM,代码行数:7,代码来源:ParameterGenerator.java


注:本文中的java.util.GregorianCalendar.clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。