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


Java GregorianCalendar.setTime方法代码示例

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


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

示例1: setDate

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void setDate(final Date date) {
    if (date == null) {
        throw new IllegalArgumentException("date may not be null");
    }

    this.currentDate = (Date) date.clone();
    this.display.setText(dateFormat.format(currentDate));

    if (this.dialog != null) {
        final GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(getDate());

        this.dialog.updateDate(
                calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH),
                calendar.get(Calendar.DAY_OF_MONTH)
        );
    }
}
 
开发者ID:PacktPublishing,项目名称:Hands-On-Android-UI-Development,代码行数:20,代码来源:DatePickerWrapper.java

示例2: writeDate

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * Write the Java Date object as a TimeRec.
 * Note that years 2000-2039 are assumed to be 00-39 per the NuFX addendum
 * at http://www.nulib.com/library/nufx-addendum.htm.
 * @see http://www.nulib.com/library/nufx-addendum.htm
 */
public void writeDate(Date date) throws IOException {
	byte[] data = null;
	if (date == null) {
		data = TIMEREC_NULL;
	} else {
		data = new byte[TIMEREC_LENGTH];
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(date);
		int year = gc.get(Calendar.YEAR);
		year -= (year < 2000) ? 1900 : 2000;
		data[TIMEREC_YEAR] = (byte)(year & 0xff);
		data[TIMEREC_MONTH] = (byte)(gc.get(Calendar.MONTH) + 1);
		data[TIMEREC_DAY] = (byte)gc.get(Calendar.DAY_OF_MONTH);
		data[TIMEREC_HOUR] = (byte)gc.get(Calendar.HOUR_OF_DAY);
		data[TIMEREC_MINUTE] = (byte)gc.get(Calendar.MINUTE);
		data[TIMEREC_SECOND] = (byte)gc.get(Calendar.SECOND);
		data[TIMEREC_WEEKDAY] = (byte)gc.get(Calendar.DAY_OF_WEEK);
	}
	write(data);
}
 
开发者ID:AppleCommander,项目名称:AppleCommander,代码行数:27,代码来源:LittleEndianByteOutputStream.java

示例3: Test4165343

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * Adding 12 months behaves differently from adding 1 year
 */
public void Test4165343() {
    GregorianCalendar calendar = new GregorianCalendar(1996, FEBRUARY, 29);
    Date start = calendar.getTime();
    logln("init date: " + start);
    calendar.add(MONTH, 12);
    Date date1 = calendar.getTime();
    logln("after adding 12 months: " + date1);
    calendar.setTime(start);
    calendar.add(YEAR, 1);
    Date date2 = calendar.getTime();
    logln("after adding one year : " + date2);
    if (date1.equals(date2)) {
        logln("Test passed");
    } else {
        errln("Test failed");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:CalendarRegression.java

示例4: loadCurrentUser

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * loads the current user that just logged in
 */
private void loadCurrentUser() {
    Intent intent = getIntent();
    user = (Profile) intent.getSerializableExtra(ID_PROFILE);
    //if (user.hasValidId())
    //    user.load();

    user.synchronize();
    //System.out.println("EVENTS-> " + user.getHabits().get(0).getEvents().get(0).getComment());
    updateAllHabits(user);

    // handle any habits that may have been missed since the user's last login
    Date currentDate = new Date();
    if (user.getLastLogin() != null && !DateUtilities.isSameDay(user.getLastLogin(), currentDate)) {
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(user.getLastLogin());

        // go through each date between the user's last login and the current date
        while (!DateUtilities.isSameDay(calendar.getTime(), currentDate)){
            // update all events at the end of that date, to make sure they are marked as missed if they weren't completed
            // on that day
            user.onDayEnd(calendar.getTime());
            calendar.add(Calendar.DATE, 1);
        }
    }

    user.setLastLogin(currentDate);
    user.save();
}
 
开发者ID:CMPUT301F17T15,项目名称:CIA,代码行数:32,代码来源:HomeTabbedActivity.java

示例5: getNthWeekdayBeforeDate

import java.util.GregorianCalendar; //导入方法依赖的package包/类
private static Date getNthWeekdayBeforeDate(Date date, Weekday weekday, int n) {
	GregorianCalendar cal = new GregorianCalendar();
	cal.setTime(date);
	int delta = getWeekdayNum(weekday) - cal.get(GregorianCalendar.DAY_OF_WEEK); // sunday ..1, monday ..2, ...
	if (delta > 0) {
		delta -= 7;
	}
	cal.add(Calendar.DATE, delta - (n - 1) * 7);
	return cal.getTime();
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:11,代码来源:DateCalc.java

示例6: handleDateTimeByYear

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * <pre>
 * 描述:间隔指定年数的指定月份指定天数后日期(例如:每年1月1日)
 * 作者:ZhangYi
 * 时间:2016年5月5日 下午4:29:07
 * 参数:(参数列表)
 * @param dateTime	指定日期
 * @param interval	间隔年(间隔几年)
 * @param month		指定月份(1-12:月份)
 * @param day		指定天数
 * @return
 * </pre>
 */
public static Date handleDateTimeByYear(Date dateTime, int interval, int month, int day) {
	try {
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(dateTime);
		calendar.add(Calendar.YEAR, interval);
		calendar.set(Calendar.MONTH, month - 1);
		calendar.set(Calendar.DAY_OF_MONTH, day);
		dateTime = calendar.getTime();
	} catch (Exception e) {
		logger.error("--间隔指定年数的指定月份指定天数后日期异常!", e);
	}
	return dateTime;
}
 
开发者ID:dev-share,项目名称:database-transform-tool,代码行数:27,代码来源:DateUtil.java

示例7: equals

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public boolean equals(Date date) {
    final GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);
    final GregorianCalendar gc2 = new GregorianCalendar();
    gc2.setTime(getDate());
    return (gc.get(GregorianCalendar.DAY_OF_YEAR) == gc2.get(GregorianCalendar.DAY_OF_YEAR)
        && gc.get(GregorianCalendar.YEAR) == gc2.get(GregorianCalendar.YEAR));
}
 
开发者ID:bcgov,项目名称:sbc-qsystem,代码行数:9,代码来源:FreeDay.java

示例8: scheduleNotification

import java.util.GregorianCalendar; //导入方法依赖的package包/类
private void scheduleNotification() {
    if (reboot.equals("none")){
        return ;
    }
    GregorianCalendar rightNow = new GregorianCalendar();
    rightNow.setLenient(true);
    rightNow.setTime(new Date());

    long nowMillis =rightNow.getTimeInMillis();
    String[] rebootTime = reboot.split(":");
    rightNow.set(Calendar.HOUR_OF_DAY, Integer.parseInt(rebootTime[0]));
    rightNow.set(Calendar.MINUTE, Integer.parseInt(rebootTime[1]));
    rightNow.set(Calendar.SECOND, Integer.parseInt(rebootTime[2]));
    long  futureInMillis =rightNow.getTimeInMillis();
    if (futureInMillis < nowMillis){
        rightNow.add(Calendar.DAY_OF_MONTH, 1);
        futureInMillis =rightNow.getTimeInMillis();
    }
    final long delay =  futureInMillis - nowMillis;
    Log.d(TAG, "INTENT: set reboot at " + rightNow );
    Timer timer = new Timer();
    timer.schedule( new TimerTask(){
        @Override
        public void run() {
            rebootNow();
        }
    }, delay);
}
 
开发者ID:msillano,项目名称:USBphpTunnel,代码行数:29,代码来源:SerialConsoleActivity.java

示例9: dropCalendar

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * Сбросить выделенные дни в календаре
 */
public void dropCalendar(int year) {
    QLog.l().logger().debug("Reset the calendar");
    final ArrayList<FreeDay> del = new ArrayList<>();
    final GregorianCalendar gc = new GregorianCalendar();
    for (FreeDay freeDay : days) {
        gc.setTime(freeDay.getDate());
        if (gc.get(GregorianCalendar.YEAR) == year) {
            del.add(freeDay);
        }
    }
    days.removeAll(del);
    fireTableDataChanged();
}
 
开发者ID:bcgov,项目名称:sbc-qsystem,代码行数:17,代码来源:CalendarTableModel.java

示例10: randomDate

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public GregorianCalendar randomDate()
{
    long date = (long)(ranGen.nextDouble()*(to-from)+from);
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(new Date(date));

    return gc;
}
 
开发者ID:SmartDataAnalytics,项目名称:Embeddable-BSBM,代码行数:9,代码来源:DateGenerator.java

示例11: writeTIME

import java.util.GregorianCalendar; //导入方法依赖的package包/类
private void writeTIME() throws IOException
{
	if (param.isModificationTimeSet())
	{
		ChunkStream cs = new ChunkStream("tIME");

		Date date = param.getModificationTime();
		TimeZone gmt = TimeZone.getTimeZone("GMT");

		GregorianCalendar cal = new GregorianCalendar(gmt);
		cal.setTime(date);

		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH);
		int day = cal.get(Calendar.DAY_OF_MONTH);
		int hour = cal.get(Calendar.HOUR_OF_DAY);
		int minute = cal.get(Calendar.MINUTE);
		int second = cal.get(Calendar.SECOND);

		cs.writeShort(year);
		cs.writeByte(month + 1);
		cs.writeByte(day);
		cs.writeByte(hour);
		cs.writeByte(minute);
		cs.writeByte(second);

		cs.writeToStream(dataOutput);
		cs.close();
	}
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:31,代码来源:mxPngImageEncoder.java

示例12: setTime

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void setTime(long value) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(new Date(value));
    if (cal.get(1) < 1980) {
        this.modDate = 33;
        this.time = 0;
        return;
    }
    this.modDate = cal.get(5);
    this.modDate = ((cal.get(2) + 1) << 5) | this.modDate;
    this.modDate = ((cal.get(1) - 1980) << 9) | this.modDate;
    this.time = cal.get(13) >> 1;
    this.time = (cal.get(12) << 5) | this.time;
    this.time = (cal.get(11) << 11) | this.time;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:16,代码来源:TinkerZipEntry.java

示例13: PostLimitOrder

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void  PostLimitOrder( TTradeRequest tradeRequest ){
    TradeType            eTradeType;
    double      CurrentPrice = -1.0;
    TTickerEntry    pNewEntry = new TTickerEntry();

    eTradeType = ConvertTradeTypeIdToEnum(tradeRequest.trade_type_id.toCharArray());

    pNewEntry.price_quote = tradeRequest.price_quote;
    pNewEntry.symbol = new String(tradeRequest.symbol);
    pNewEntry.trade_qty = LIMIT_TRIGGER_TRADE_QTY;

    CurrentPrice = priceBoard.getCurrentPrice( tradeRequest.symbol ).getDollars();

    if((( eTradeType == TradeType.eLimitBuy || eTradeType == TradeType.eStopLoss ) &&
            CurrentPrice <= tradeRequest.price_quote )
        ||
            (( eTradeType == TradeType.eLimitSell ) &&
            CurrentPrice >= tradeRequest.price_quote )){
        pNewEntry.price_quote = CurrentPrice;
        limitOrderTimers.processExpiredTimers();
        inTheMoneyLimitOrderQ.add(pNewEntry);
    }
    else{
        pNewEntry.price_quote = tradeRequest.price_quote;
        double TriggerTimeDelay;
        GregorianCalendar currGreTime = new GregorianCalendar();
        GregorianCalendar baseGreTime = new GregorianCalendar();
        currGreTime.setTime(currentTime);
        baseGreTime.setTime(baseTime);
        double fCurrentTime = currGreTime.getTimeInMillis() - baseGreTime.getTimeInMillis();
        //TODO the third para, compare to c++
        TriggerTimeDelay = priceBoard.getSubmissionTime(pNewEntry.symbol, fCurrentTime, new EGenMoney(pNewEntry.price_quote), eTradeType) - fCurrentTime;
        limitOrderTimers.startTimer( TriggerTimeDelay);
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:36,代码来源:MEETickerTape.java

示例14: handleDateTimeByMonth

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * <pre>
 * 描述:间隔指定月数的指定天数后日期(例如:每月1日)
 * 作者:ZhangYi
 * 时间:2016年5月5日 下午4:29:07
 * 参数:(参数列表)
 * @param dateTime	指定日期
 * @param interval	间隔月数(间隔几个月)
 * @param day		指定天数
 * @return
 * </pre>
 */
public static Date handleDateTimeByMonth(Date dateTime, int interval, int day) {
	try {
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(dateTime);
		calendar.add(Calendar.MONTH, interval);
		calendar.set(Calendar.DAY_OF_MONTH, day);
		dateTime = calendar.getTime();
	} catch (Exception e) {
		logger.error("--间隔指定月数的指定天数后日期异常!", e);
	}
	return dateTime;
}
 
开发者ID:dev-share,项目名称:css-elasticsearch,代码行数:25,代码来源:DateUtil.java

示例15: handleDateTimeByDay

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * <pre>
 * 描述:间隔指定天数后日期(例如:每3天)
 * 作者:ZhangYi
 * 时间:2016年5月5日 下午4:29:07
 * 参数:(参数列表)
 * @param dateTime	指定日期
 * @param interval	间隔天数
 * @return
 * </pre>
 */
public static Date handleDateTimeByDay(Date dateTime, int interval) {
	try {
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(dateTime);
		calendar.add(Calendar.DAY_OF_MONTH, interval);
		dateTime = calendar.getTime();
	} catch (Exception e) {
		logger.error("--间隔指定天数后日期异常!", e);
	}
	return dateTime;
}
 
开发者ID:dev-share,项目名称:database-transform-tool,代码行数:23,代码来源:DateUtil.java


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