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


Java Calendar.set方法代码示例

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


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

示例1: addDayOfMonth

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 日期加上天数
 * @param date
 * @param dateFormat
 * @param numDay
 * @return
 */
public String addDayOfMonth(String date, DateFormat dateFormat, int numDay){

    SimpleDateFormat df = new SimpleDateFormat(dateFormat.getValue());
    Calendar c = Calendar.getInstance();
    try {
        c.setTime(df.parse(date));
        c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + numDay);

        return df.format(c.getTime());
    } catch (ParseException e) {
        e.printStackTrace();
        System.err.print(e);
        return null;
    }
}
 
开发者ID:Shmilyz,项目名称:Swap,代码行数:23,代码来源:DateUtil.java

示例2: 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

示例3: calculateAlarm

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * Given an alarm in hours and minutes, return a time suitable for
 * setting in AlarmManager.
 */
static Calendar calculateAlarm(int hour, int minute,
                               Alarm.DaysOfWeek daysOfWeek) {

  // start with now
  Calendar c = Calendar.getInstance();
  c.setTimeInMillis(System.currentTimeMillis());

  int nowHour = c.get(Calendar.HOUR_OF_DAY);
  int nowMinute = c.get(Calendar.MINUTE);

  // if alarm is behind current time, advance one day
  if (hour < nowHour
      || hour == nowHour && minute <= nowMinute) {
    c.add(Calendar.DAY_OF_YEAR, 1);
  }
  c.set(Calendar.HOUR_OF_DAY, hour);
  c.set(Calendar.MINUTE, minute);
  c.set(Calendar.SECOND, 0);
  c.set(Calendar.MILLISECOND, 0);

  int addDays = daysOfWeek.getNextAlarm(c);
  if (addDays > 0) c.add(Calendar.DAY_OF_WEEK, addDays);
  return c;
}
 
开发者ID:nordfalk,项目名称:EsperantoRadio,代码行数:29,代码来源:Alarms.java

示例4: getSomeMonthsBefore

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 获取本日的n个月前的日期,如本日=2015-03-01,n=3,则输出2014-12-01
 *
 * @param n
 * @return
 */
public static Date getSomeMonthsBefore(int n) {
    Calendar cl = Calendar.getInstance();
    cl.set(Calendar.HOUR_OF_DAY, 0);
    cl.set(Calendar.MINUTE, 0);
    cl.set(Calendar.SECOND, 0);
    cl.set(Calendar.MILLISECOND, 0);

    int year = cl.get(Calendar.YEAR);
    int month = cl.get(Calendar.MONTH);
    int day = cl.get(Calendar.DAY_OF_MONTH);
    int by = n / 12;
    int bm = n % 12;
    if (by > 0) {
        year -= by;
    }
    if (bm > month) {
        year--;
    }
    month = (12 + month - bm) % 12;
    cl.set(Calendar.YEAR, year);
    cl.set(Calendar.MONTH, month);
    cl.set(Calendar.DAY_OF_MONTH, 1);
    if (day > cl.getActualMaximum(Calendar.DAY_OF_MONTH)) {//cl为n个月前的1号,如果该月的最大日数比现在的日数小,则取当月的最大日数
        cl.set(Calendar.DAY_OF_MONTH, cl.getActualMaximum(Calendar.DAY_OF_MONTH));
    } else {
        cl.set(Calendar.DAY_OF_MONTH, day);
    }
    return cl.getTime();
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:36,代码来源:TimeUtils.java

示例5: getLastYearMonths

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 获取最近1年所有月份数据
 * 
 * @return
 */
public static List<String> getLastYearMonths() {
	List<String> list_res = new ArrayList<String>();
	Calendar cal = Calendar.getInstance();
	cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1); // 要先+1,才能把本月的算进去</span>
	for (int i = 0; i < 12; i++) {
		cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1); // 逐次往前推1个月
		list_res.add(cal.get(Calendar.YEAR) + "-" + fillZero((cal.get(Calendar.MONTH) + 1) + "", 2));
	}
	return list_res;
}
 
开发者ID:noseparte,项目名称:Spring-Boot-Server,代码行数:16,代码来源:DateUtils.java

示例6: setStartTime

import java.util.Calendar; //导入方法依赖的package包/类
private synchronized static void setStartTime(long millis) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(millis);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    startTime = cal.getTimeInMillis();
    cal.add(Calendar.MONTH, 1);
    nextStartTime = cal.getTimeInMillis();
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:13,代码来源:MessageClientIDSetter.java

示例7: hourEndTime

import java.util.Calendar; //导入方法依赖的package包/类
public static Date hourEndTime(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTime();
}
 
开发者ID:Wangsu-Cloud-Storage,项目名称:wcs-android-sdk,代码行数:9,代码来源:DateUtil.java

示例8: loadMonth

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * This method fill calendar GridView with days
 *
 * @param position Position of current page in ViewPager
 */
private void loadMonth(int position) {
    ArrayList<Date> days = new ArrayList<>();

    // Get Calendar object instance
    Calendar calendar = (Calendar) mCalendarProperties.getCurrentDate().clone();

    // Add months to Calendar (a number of months depends on ViewPager position)
    calendar.add(Calendar.MONTH, position);

    // Set day of month as 1
    calendar.set(Calendar.DAY_OF_MONTH, 1);

    // Get a number of the first day of the week
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

    // Count when month is beginning
    int monthBeginningCell = dayOfWeek + (dayOfWeek == 1 ? 5 : -2);

    // Subtract a number of beginning days, it will let to load a part of a previous month
    calendar.add(Calendar.DAY_OF_MONTH, -monthBeginningCell);

    /*
    Get all days of one page (42 is a number of all possible cells in one page
    (a part of previous month, current month and a part of next month))
     */
    while (days.size() < 42) {
        days.add(calendar.getTime());
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }

    mPageMonth = calendar.get(Calendar.MONTH) - 1;
    CalendarDayAdapter calendarDayAdapter = new CalendarDayAdapter(this, mContext,
            mCalendarProperties, days, mPageMonth);

    mCalendarGridView.setAdapter(calendarDayAdapter);
}
 
开发者ID:Applandeo,项目名称:Material-Calendar-View,代码行数:42,代码来源:CalendarPageAdapter.java

示例9: getFirstDayOfMonth

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 返回月的第一天
 * 
 * @return
 */
public static long getFirstDayOfMonth()
{
	Calendar calendar = new GregorianCalendar();

	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);

	Log.D(TAG, "getFirstDayOfMonth: " + calendar.getTime());
	return calendar.getTimeInMillis();
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:20,代码来源:DateUtils.java

示例10: testBug15604

import java.util.Calendar; //导入方法依赖的package包/类
public void testBug15604() throws Exception {
    createTable("testBug15604_date_cal", "(field1 DATE)");
    Properties props = new Properties();
    props.setProperty("useLegacyDatetimeCode", "false");
    props.setProperty("sessionVariables", "time_zone='America/Chicago'");

    Connection nonLegacyConn = getConnectionWithProps(props);

    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

    cal.set(Calendar.YEAR, 2005);
    cal.set(Calendar.MONTH, 4);
    cal.set(Calendar.DAY_OF_MONTH, 15);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    java.sql.Date sqlDate = new java.sql.Date(cal.getTime().getTime());

    Calendar cal2 = Calendar.getInstance();
    cal2.setTime(sqlDate);
    System.out.println(new java.sql.Date(cal2.getTime().getTime()));
    this.pstmt = nonLegacyConn.prepareStatement("INSERT INTO testBug15604_date_cal VALUES (?)");

    this.pstmt.setDate(1, sqlDate, cal);
    this.pstmt.executeUpdate();
    this.rs = nonLegacyConn.createStatement().executeQuery("SELECT field1 FROM testBug15604_date_cal");
    this.rs.next();

    assertEquals(sqlDate.getTime(), this.rs.getDate(1, cal).getTime());
}
 
开发者ID:JuanJoseFJ,项目名称:ProyectoPacientes,代码行数:33,代码来源:ResultSetRegressionTest.java

示例11: bcdbuf2Date

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * Translate bcd buffer to GMT time
 *
 * @param buffer byte[]{year-2000,month,day_of_month,hour_of_day,minute,seconds}
 * @param offset The postion where buffer to translate from
 * @return The GMT time encode by bcd
 * @throws Exception The time need 6 unsigned8bit at least, if the buffer avaible size less than 6, this will happen
 */
public static long bcdbuf2Date(byte[] buffer, int offset) throws Exception {
    if (buffer.length - offset < 6) {
        throw new Exception("buffer length is not enough");
    }
    Calendar now = Calendar.getInstance();
    now.set(Calendar.YEAR, BCDUtil.bcd2value(buffer, offset + 0, 1) + 2000);
    now.set(Calendar.MONTH, BCDUtil.bcd2value(buffer, offset + 1, 1) - 1);
    now.set(Calendar.DAY_OF_MONTH, BCDUtil.bcd2value(buffer, offset + 2, 1));
    now.set(Calendar.HOUR_OF_DAY, BCDUtil.bcd2value(buffer, offset + 3, 1));
    now.set(Calendar.MINUTE, BCDUtil.bcd2value(buffer, offset + 4, 1));
    now.set(Calendar.SECOND, BCDUtil.bcd2value(buffer, offset + 5, 1));
    now.set(Calendar.MILLISECOND, 0);
    return now.getTimeInMillis();
}
 
开发者ID:ioprotocol,项目名称:engine,代码行数:23,代码来源:ByteBufferUtil.java

示例12: test50

import java.util.Calendar; //导入方法依赖的package包/类
@Test
public void test50() {
    Calendar cal = Calendar.getInstance();
    Timestamp ts1 = new Timestamp(System.currentTimeMillis());
    cal.setTimeInMillis(ts1.getTime());
    cal.add(Calendar.MONTH, -1);
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
    Timestamp ts2 = new Timestamp(cal.getTimeInMillis());
    assertTrue(!ts1.equals(ts2) && ts1.equals(ts1));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:TimestampTests.java

示例13: daylightSavingHourShiftOccurredAndAdvanceNeeded

import java.util.Calendar; //导入方法依赖的package包/类
private boolean daylightSavingHourShiftOccurredAndAdvanceNeeded(Calendar newTime, int initialHourOfDay, Date afterTime) {
    if(isPreserveHourOfDayAcrossDaylightSavings() && newTime.get(Calendar.HOUR_OF_DAY) != initialHourOfDay) {
        newTime.set(Calendar.HOUR_OF_DAY, initialHourOfDay);
        if (newTime.get(Calendar.HOUR_OF_DAY) != initialHourOfDay) {
            return isSkipDayIfHourDoesNotExist();
        } else {
            return !newTime.getTime().after(afterTime);
        }
    }
    return false;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:CalendarIntervalTriggerImpl.java

示例14: getMonthStartDate

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 获取本月的第一天
 *
 * @return
 */
public static String getMonthStartDate() {
    SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.getTime();
    return dateFormater.format(cal.getTime()) + "";
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:13,代码来源:TimeUtils.java

示例15: getTime

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * 根据年月日时分秒毫秒获取时间
 * @param year
 * @param month
 * @param date
 * @param hour
 * @param minute
 * @param second
 * @param millisecond
 * @return
 */
public static long getTime(int year, int month, int date, int hour, int minute, int second, int millisecond) {
	Calendar calendar = Calendar.getInstance();
	calendar.set(Calendar.YEAR, year);
	calendar.set(Calendar.MONTH, month - 1 + Calendar.JANUARY);
	calendar.set(Calendar.DATE, date);
	calendar.set(Calendar.HOUR_OF_DAY, hour);
	calendar.set(Calendar.MINUTE, minute);
	calendar.set(Calendar.SECOND, second);
	calendar.set(Calendar.MILLISECOND, millisecond);
	return calendar.getTimeInMillis();
}
 
开发者ID:AnnyBaby,项目名称:Mvp-Retrofit-Rxjava-Rxbus,代码行数:23,代码来源:DateUtils.java


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