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


Java Calendar.setTime方法代碼示例

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


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

示例1: getDaysCode

import java.util.Calendar; //導入方法依賴的package包/類
public int getDaysCode(Event event) {
    int daysCode = 0;
    for (Iterator i=event.getMeetings().iterator();i.hasNext();) {
        Meeting meeting = (Meeting)i.next();
        Calendar date = Calendar.getInstance(Locale.US);
        date.setTime(meeting.getMeetingDate());
        switch (date.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.MONDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_MON]; break;
        case Calendar.TUESDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_TUE]; break;
        case Calendar.WEDNESDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_WED]; break;
        case Calendar.THURSDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_THU]; break;
        case Calendar.FRIDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_FRI]; break;
        case Calendar.SATURDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_SAT]; break;
        case Calendar.SUNDAY : daysCode |= Constants.DAY_CODES[Constants.DAY_SUN]; break;
        }
    }
    return daysCode;
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:19,代碼來源:MakeAssignmentsForClassEvents.java

示例2: getDayBetween

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * 間隔天數
 * 
 * @param startDate
 * @param endDate
 * @return
 */
public static final Integer getDayBetween(Date startDate, Date endDate) {
	Calendar start = Calendar.getInstance();
	start.setTime(startDate);
	start.set(Calendar.HOUR_OF_DAY, 0);
	start.set(Calendar.MINUTE, 0);
	start.set(Calendar.SECOND, 0);
	start.set(Calendar.MILLISECOND, 0);
	Calendar end = Calendar.getInstance();
	end.setTime(endDate);
	end.set(Calendar.HOUR_OF_DAY, 0);
	end.set(Calendar.MINUTE, 0);
	end.set(Calendar.SECOND, 0);
	end.set(Calendar.MILLISECOND, 0);

	long n = end.getTimeInMillis() - start.getTimeInMillis();
	return (int) (n / (60 * 60 * 24 * 1000l));
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:25,代碼來源:DateUtil.java

示例3: getDay

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * 年月日
 * @param date
 * @return
 */
public static String getDay(Date date) {
	TimeZone t = TimeZone.getTimeZone("GMT+08:00");// 獲取東8區TimeZone
	Calendar calendar = Calendar.getInstance(t);
	if (date == null) {
		calendar.setTimeInMillis(System.currentTimeMillis());
	} else {
		calendar.setTime(date);
	}
	int year = calendar.get(Calendar.YEAR);
	int month = calendar.get(Calendar.MONTH) + 1;
	int day = calendar.get(Calendar.DAY_OF_MONTH);

	String time = year + "-" + (month < 10 ? "0" : "") + month + '-' + (day < 10 ? "0" : "") + day;
	return time;
}
 
開發者ID:PlutoArchitecture,項目名稱:Pluto-Android,代碼行數:21,代碼來源:DateUtil.java

示例4: addTimeToDate

import java.util.Calendar; //導入方法依賴的package包/類
private Date addTimeToDate(int mins){
    Date date = new Date();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(Calendar.MINUTE, mins);
    return calendar.getTime();
}
 
開發者ID:kotlin-korea,項目名稱:Minimal-Todo,代碼行數:8,代碼來源:ReminderActivity.java

示例5: main

import java.util.Calendar; //導入方法依賴的package包/類
public static void main(String[] args) throws ParseException
{

    Map map=new HashMap<>()  ;
    Date beginDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2014-01-04 00:00:01");
    for (int i = 0; i < 60*60*24*10; i++)
    {


        Calendar cal = Calendar.getInstance();
        cal.setTime(beginDate);
       cal.add(Calendar.SECOND, 1);
        beginDate = cal.getTime();
        int hash = hash(beginDate.getTime(), 3);
        if(map.containsKey(hash))
        {
        map.put(hash,    (int)map.get(hash)+1);
        } else
        {
            map.put(hash,1);
        }
      //  System.out.println(hash);
    }


    System.out.println(map.values());
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:28,代碼來源:PartitionByRangeDateHashTest.java

示例6: calculateExpiryDate

import java.util.Calendar; //導入方法依賴的package包/類
public EmailVerification calculateExpiryDate() {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Timestamp(cal.getTime().getTime()));
    cal.add(Calendar.MINUTE, EXPIRATION);
    this.expiryDate = new Date(cal.getTime().getTime());
    return this;
}
 
開發者ID:quebic-source,項目名稱:microservices-sample-project,代碼行數:8,代碼來源:EmailVerification.java

示例7: getYearFromDate

import java.util.Calendar; //導入方法依賴的package包/類
public static int getYearFromDate(Date date) {
	int year = 1990;

	if (date != null) {
		Calendar calendar = Calendar.getInstance();

		calendar.setTime(date);
		year = calendar.get(Calendar.YEAR);

		calendar.setTime(date);
		year = calendar.get(Calendar.YEAR);
	}

	return year;
}
 
開發者ID:VietOpenCPS,項目名稱:opencps-v2,代碼行數:16,代碼來源:DateTimeUtils.java

示例8: getYearStart

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * 得到當前年起始時間
 * 
 * @param date
 * @return
 */
public static Date getYearStart(Date date) {
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(date);
	calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR));
	calendar.set(Calendar.MONTH, 0);
	calendar.set(Calendar.DAY_OF_MONTH, 1);
	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	calendar.set(Calendar.MILLISECOND, 0);
	return calendar.getTime();
}
 
開發者ID:babymm,項目名稱:mumu,代碼行數:19,代碼來源:DateUtils.java

示例9: runBaseQuery

import java.util.Calendar; //導入方法依賴的package包/類
private HashMap<String, Long> runBaseQuery(Date date){
    Calendar cal = Calendar.getInstance();
    long DIFF, TIME = System.currentTimeMillis(), START_TIME = System.currentTimeMillis();
    Query baseQuery = em.createQuery(BASE_QUERY);
    HashMap<String, Long> result = new HashMap<String, Long>();
    {
        cal.setTime(date);
        int dayMin = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
        int dayMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        cal.set(Calendar.DAY_OF_MONTH, dayMin);
        Parameter<Date> p1 = baseQuery.getParameter("oldStartDate", Date.class);
        baseQuery.setParameter(p1, cal.getTime());
        cal.set(Calendar.DAY_OF_MONTH, dayMax);
        Parameter<Date> p2 = baseQuery.getParameter("oldEndDate", Date.class);
        baseQuery.setParameter(p2, cal.getTime());

        List<Object[]> resultList = baseQuery.getResultList();

        DIFF = (System.currentTimeMillis() - TIME);
        System.out.println("    Q TIME = "+DIFF+"ms");

        for (int i=0; i < resultList.size(); i++){
            Object o[] = resultList.get(i);
            result.put((String)o[1],(Long)o[0]);
        }
    }
    return result;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:29,代碼來源:DailySalesHeatMapFacadeREST.java

示例10: hourAndMinuteFromDate

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Create a TimeOfDay from the given date (at the zero-second), in the system default TimeZone.
 * 
 * @param dateTime The java.util.Date from which to extract Hour and Minute.
 * @param tz The TimeZone from which relate Hour and Minute for the given date.  If null, system default
 * TimeZone will be used.
 */
public static TimeOfDay hourAndMinuteFromDate(Date dateTime, TimeZone tz) {
    if (dateTime == null)
        return null;
    Calendar cal = Calendar.getInstance();
    cal.setTime(dateTime);
    if(tz != null)
        cal.setTimeZone(tz);
    
    return new TimeOfDay(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE));
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:TimeOfDay.java

示例11: isToday

import java.util.Calendar; //導入方法依賴的package包/類
public static boolean isToday(Date date) {
    Calendar dt1 = getCalendar();
    Calendar dt2 = getCalendar();
    dt2.setTime(date);
    if ((dt1.get(Calendar.MONTH) == dt2.get(Calendar.MONTH)) && (dt1.get(Calendar.DAY_OF_MONTH) == dt2.get(Calendar.DAY_OF_MONTH))) {
        return true;
    }
    return false;
}
 
開發者ID:zerosoft,項目名稱:CodeBroker,代碼行數:10,代碼來源:TimeUtil.java

示例12: reserve

import java.util.Calendar; //導入方法依賴的package包/類
@Override
public Observable<String> reserve(ReserveOption option) {
    DateFormat dateFormat = new SimpleDateFormat("ddMMyyyy HHmm");
    String startDate = dateFormat.format(option.getDatetime());
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(option.getDatetime());
    calendar.add(Calendar.HOUR,option.getDuration());
    String endDate = dateFormat.format(calendar.getTime());
    String duration = String.valueOf(option.getDuration());

    return sessionRepo.getSession().flatMap( s ->
            remoteSource.reserve(option.getCode(),option.getName(),startDate,endDate,duration,s.getUserCode(),s.getToken()));
}
 
開發者ID:Bruno125,項目名稱:Unofficial-Ups,代碼行數:14,代碼來源:UpcUniversityInfoRepository.java

示例13: main3

import java.util.Calendar; //導入方法依賴的package包/類
public static void main3(String[] args) throws ParseException {
    Date startDateTime = DateUtil.parserToSecond("2013-05-13 14:02:42");
    Date endDateTime = DateUtil.parserToSecond("2013-05-17 12:02:42");
    String startHHmmStr = DateUtil.formatToHHmm(startDateTime);
    String startDayStr = DateUtil.formatToDay(startDateTime);
    String endHHmmStr = DateUtil.formatToHHmm(endDateTime);
    String endDayStr = DateUtil.formatToDay(endDateTime);
    // 得到二個日期間的間隔天數
    long day = (endDateTime.getTime() - startDateTime.getTime())
            / (24 * 60 * 60 * 1000);
    // 開始那天
    String tStart = startDayStr + "==" + startHHmmStr + "-"
            + DateUtil.formatToHHmm(DateUtil.getCurrEnd(startDateTime));
    System.out.println(tStart);

    // 中間那些天
    for (int i = 0; i < day; i++) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startDateTime);
        calendar.roll(Calendar.DATE, i + 1);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = sdf.parse(sdf.format(calendar.getTime()));
        String tMiddle = DateUtil.formatToDay(date) + "=="
                + DateUtil.formatToHHmm(DateUtil.getCurrStart(date)) + "-"
                + DateUtil.formatToHHmm(DateUtil.getCurrEnd(date));
        System.out.println(i + 1 + "--" + tMiddle);
    }

    // 結束那天
    String tEnd = endDayStr + "=="
            + DateUtil.formatToHHmm(DateUtil.getCurrStart(endDateTime))
            + "-" + endHHmmStr;
    System.out.println(tEnd);

}
 
開發者ID:Datatellit,項目名稱:xlight_android_native,代碼行數:36,代碼來源:DateUtil.java

示例14: next

import java.util.Calendar; //導入方法依賴的package包/類
/**
 * Get the next {@link Date} in the sequence matching the Cron pattern and
 * after the value provided. The return value will have a whole number of
 * seconds, and will be after the input value.
 * @param date a seed value
 * @return the next value matching the pattern
 */
public Date next(Date date) {
	/*
	The plan:

	1 Round up to the next whole second

	2 If seconds match move on, otherwise find the next match:
	2.1 If next match is in the next minute then roll forwards

	3 If minute matches move on, otherwise find the next match
	3.1 If next match is in the next hour then roll forwards
	3.2 Reset the seconds and go to 2

	4 If hour matches move on, otherwise find the next match
	4.1 If next match is in the next day then roll forwards,
	4.2 Reset the minutes and seconds and go to 2

	...
	*/

	Calendar calendar = new GregorianCalendar();
	calendar.setTimeZone(this.timeZone);
	calendar.setTime(date);

	// First, just reset the milliseconds and try to calculate from there...
	calendar.set(Calendar.MILLISECOND, 0);
	long originalTimestamp = calendar.getTimeInMillis();
	doNext(calendar, calendar.get(Calendar.YEAR));

	if (calendar.getTimeInMillis() == originalTimestamp) {
		// We arrived at the original timestamp - round up to the next whole second and try again...
		calendar.add(Calendar.SECOND, 1);
		doNext(calendar, calendar.get(Calendar.YEAR));
	}

	return calendar.getTime();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:45,代碼來源:CronSequenceGenerator.java

示例15: test_kr_2

import java.util.Calendar; //導入方法依賴的package包/類
public void test_kr_2() throws Exception {
    Entity vo = JSON.parseObject("{\"date\":\"2016년5월06일\"}", Entity.class);

    Calendar calendar = Calendar.getInstance(JSON.defaultTimeZone, JSON.defaultLocale);
    calendar.setTime(vo.date);
    Assert.assertEquals(2016, calendar.get(Calendar.YEAR));
    Assert.assertEquals(4, calendar.get(Calendar.MONTH));
    Assert.assertEquals(6, calendar.get(Calendar.DAY_OF_MONTH));
    Assert.assertEquals(0, calendar.get(Calendar.HOUR_OF_DAY));
    Assert.assertEquals(0, calendar.get(Calendar.MINUTE));
    Assert.assertEquals(0, calendar.get(Calendar.SECOND));
    Assert.assertEquals(0, calendar.get(Calendar.MILLISECOND));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:DateFieldTest9.java


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