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


Java GregorianCalendar.set方法代码示例

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


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

示例1: getDateValue

import java.util.GregorianCalendar; //导入方法依赖的package包/类
private Date getDateValue(int year, int month, int day, int hours, int minutes, int sec, int msec, int offsetInMinutes)
{
    // minute in millis
    int millisInMinute = 1000 * 60;

    GregorianCalendar gc = new GregorianCalendar();

    // set correct offset
    String[] tzArray = TimeZone.getAvailableIDs(millisInMinute * offsetInMinutes);
    if (tzArray.length > 0)
    {
        gc.setTimeZone(TimeZone.getTimeZone(tzArray[0]));
    }

    // set date
    gc.set(GregorianCalendar.YEAR, year);
    gc.set(GregorianCalendar.MONTH, month - 1);
    gc.set(GregorianCalendar.DAY_OF_MONTH, day);
    gc.set(GregorianCalendar.HOUR_OF_DAY, hours);
    gc.set(GregorianCalendar.MINUTE, minutes);
    gc.set(GregorianCalendar.SECOND, sec);
    gc.set(GregorianCalendar.MILLISECOND, msec);

    return gc.getTime();
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:26,代码来源:ISO8601DateFormatTest.java

示例2: isBefore

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * Compare two dates without looking at their time component
 * @param one the first date to compare
 * @param two the second date to compare
 * @return whether the first date is before the second one
 */
public static boolean isBefore(Date one, Date two){
    if (one == null || two == null)
        return false;

    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTime(one);
    gc1.set(Calendar.HOUR, 2);
    gc1.set(Calendar.MINUTE, 1);
    gc1.set(Calendar.SECOND, 1);

    GregorianCalendar gc2 = new GregorianCalendar();
    gc2.setTime(two);
    gc2.set(Calendar.HOUR, 2);
    gc2.set(Calendar.MINUTE, 1);
    gc2.set(Calendar.SECOND, 1);

    return gc1.getTime().before(gc2.getTime());
}
 
开发者ID:CMPUT301F17T15,项目名称:CIA,代码行数:25,代码来源:DateUtilities.java

示例3: test_IsoChrono_vsCalendar

import java.util.GregorianCalendar; //导入方法依赖的package包/类
@Test(dataProvider = "RangeVersusCalendar")
public void test_IsoChrono_vsCalendar(LocalDate isoStartDate, LocalDate isoEndDate) {
    GregorianCalendar cal = new GregorianCalendar();
    assertEquals(cal.getCalendarType(), "gregory", "Unexpected calendar type");
    LocalDate isoDate = IsoChronology.INSTANCE.date(isoStartDate);

    cal.setTimeZone(TimeZone.getTimeZone("GMT+00"));
    cal.set(Calendar.YEAR, isoDate.get(YEAR));
    cal.set(Calendar.MONTH, isoDate.get(MONTH_OF_YEAR) - 1);
    cal.set(Calendar.DAY_OF_MONTH, isoDate.get(DAY_OF_MONTH));

    while (isoDate.isBefore(isoEndDate)) {
        assertEquals(isoDate.get(DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH), "Day mismatch in " + isoDate + ";  cal: " + cal);
        assertEquals(isoDate.get(MONTH_OF_YEAR), cal.get(Calendar.MONTH) + 1, "Month mismatch in " + isoDate);
        assertEquals(isoDate.get(YEAR_OF_ERA), cal.get(Calendar.YEAR), "Year mismatch in " + isoDate);

        isoDate = isoDate.plus(1, ChronoUnit.DAYS);
        cal.add(Calendar.DAY_OF_MONTH, 1);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TestIsoChronoImpl.java

示例4: _getDates

import java.util.GregorianCalendar; //导入方法依赖的package包/类
private static Date[] _getDates(
  Locale[] locales,
  TimeZone[] timeZones,
  int[] day,
  int[] month,
  int[] year,
  int[] hours,
  int[] mins,
  int[] secs
  )
{
  Date[] dates = new Date[timeZones.length];
  for (int i = 0; i < timeZones.length; ++i)
  {
    GregorianCalendar gcal = new GregorianCalendar();
    gcal.set(year[i],month[i],day[i],hours[i],mins[i],secs[i]);
    gcal.setTimeZone(timeZones[i]);
    dates[i] = gcal.getTime();
  }
  return dates;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:22,代码来源:DateTimeConverterTestCase.java

示例5: getToday

import java.util.GregorianCalendar; //导入方法依赖的package包/类
Pair<Date, Date> getToday() {
    final GregorianCalendar today = new GregorianCalendar();
    today.set(Calendar.HOUR_OF_DAY, today.getActualMaximum(Calendar.HOUR_OF_DAY));
    today.set(Calendar.MINUTE, today.getActualMaximum(Calendar.MINUTE));
    today.set(Calendar.SECOND, today.getActualMaximum(Calendar.SECOND));
    today.set(Calendar.MILLISECOND, today.getActualMaximum(Calendar.MILLISECOND));

    final Date end = today.getTime();
    today.add(Calendar.DATE, -1);
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);

    return new Pair<>(today.getTime(), end);
}
 
开发者ID:PacktPublishing,项目名称:Hands-On-Android-UI-Development,代码行数:17,代码来源:AllowanceOverviewPresenter.java

示例6: handleDateTimeByYear

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

示例7: getThisWeek

import java.util.GregorianCalendar; //导入方法依赖的package包/类
Pair<Date, Date> getThisWeek() {
    final GregorianCalendar today = new GregorianCalendar();
    today.set(Calendar.HOUR_OF_DAY, today.getActualMaximum(Calendar.HOUR_OF_DAY));
    today.set(Calendar.MINUTE, today.getActualMaximum(Calendar.MINUTE));
    today.set(Calendar.SECOND, today.getActualMaximum(Calendar.SECOND));
    today.set(Calendar.MILLISECOND, today.getActualMaximum(Calendar.MILLISECOND));

    final Date end = today.getTime();
    today.add(Calendar.DATE, -(today.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY));

    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);

    return new Pair<>(today.getTime(), end);
}
 
开发者ID:PacktPublishing,项目名称:Hands-On-Android-UI-Development,代码行数:18,代码来源:AllowanceOverviewPresenter.java

示例8: TestRog

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

    int year = 1997, month = APRIL, date = 1;
    gc.set(year, month, date); // April 1, 1997

    gc.set(HOUR_OF_DAY, 23);
    gc.set(MINUTE, 0);
    gc.set(SECOND, 0);
    gc.set(MILLISECOND, 0);

    for (int i = 0; i < 9; i++, gc.add(DATE, 1)) {
        if (gc.get(YEAR) != year
                || gc.get(MONTH) != month
                || gc.get(DATE) != (date + i)) {
            errln("FAIL: Date " + gc.getTime() + " wrong");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:CalendarTest.java

示例9: handleDateTimeByMonth

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * <pre>
 * 描述:间隔指定月数的指定周数指定星期数后日期(例如:每3个月第一个星期一)
 * 作者:ZhangYi
 * 时间:2016年5月5日 下午4:29:07
 * 参数:(参数列表)
 * @param dateTime	指定日期
 * @param interval	间隔月数(间隔几个月)
 * @param num		指定周数(1-4:第几个星期)
 * @param week		指定周几(1-7:周一至周日,-1:不指定周几(JDK默认星期一))
 * @return
 * </pre>
 */
public static Date handleDateTimeByMonth(Date dateTime, int interval, int num, int week) {
	try {
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(dateTime);
		calendar.add(Calendar.MONTH, interval);
		if (num < 0) {// 最后一个星期
			calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, -1);
		} else {
			calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, num);
		}
		if (week < 0) {// [默认星期一]
			calendar.set(Calendar.DAY_OF_WEEK, 1 % 7 + 1);
		} else {
			calendar.set(Calendar.DAY_OF_WEEK, week % 7 + 1);
		}
		dateTime = calendar.getTime();
	} catch (Exception e) {
		logger.error("--间隔指定月数的指定周数指定星期数后日期异常!", e);
	}
	return dateTime;
}
 
开发者ID:dev-share,项目名称:database-transform-tool,代码行数:35,代码来源:DateUtil.java

示例10: TestFieldSet4781

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void TestFieldSet4781() {
    try {
        GregorianCalendar g = new GregorianCalendar();
        GregorianCalendar g2 = new GregorianCalendar();
        // At this point UTC value is set, various fields are not.
        // Now set to noon.
        g2.set(HOUR, 12);
        g2.set(MINUTE, 0);
        g2.set(SECOND, 0);
        // At this point the object thinks UTC is NOT set, but fields are set.
        // The following line will result in IllegalArgumentException because
        // it thinks the YEAR is set and it is NOT.
        if (g2.equals(g)) {
            logln("Same");
        } else {
            logln("Different");
        }
    } catch (IllegalArgumentException e) {
        errln("Unexpected exception seen: " + e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:CalendarTest.java

示例11: Test4162587

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * Calendar and Date HOUR broken.  If HOUR is out-of-range, Calendar
 * and Date classes will misbehave.
 */
public void Test4162587() {
    TimeZone savedTz = TimeZone.getDefault();
    TimeZone tz = TimeZone.getTimeZone("PST");
    TimeZone.setDefault(tz);
    GregorianCalendar cal = new GregorianCalendar(tz);
    Date d;

    try {
        for (int i = 0; i < 5; ++i) {
            if (i > 0) {
                logln("---");
            }

            cal.clear();
            cal.set(1998, APRIL, 5, i, 0);
            d = cal.getTime();
            String s0 = d.toString();
            logln("0 " + i + ": " + s0);

            cal.clear();
            cal.set(1998, APRIL, 4, i + 24, 0);
            d = cal.getTime();
            String sPlus = d.toString();
            logln("+ " + i + ": " + sPlus);

            cal.clear();
            cal.set(1998, APRIL, 6, i - 24, 0);
            d = cal.getTime();
            String sMinus = d.toString();
            logln("- " + i + ": " + sMinus);

            if (!s0.equals(sPlus) || !s0.equals(sMinus)) {
                errln("Fail: All three lines must match");
            }
        }
    } finally {
        TimeZone.setDefault(savedTz);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:44,代码来源:CalendarRegression.java

示例12: testPreviousStandardDateDay

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * A basic check for the testPreviousStandardDate() method when the
 * tick unit is 1 day.
 */
public void testPreviousStandardDateDay() {
    MyDateAxis axis = new MyDateAxis("Day");
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.set(2006, Calendar.AUGUST, 25, 12, 0);
    Date d1 = calendar.getTime();
    calendar.set(2007, Calendar.MAY, 20, 12, 0);
    Date d2 = calendar.getTime();
    axis.setRange(d1, d2);
    DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 1);
    axis.setTickUnit(unit);
    
    axis.setTickMarkPosition(DateTickMarkPosition.START);
    Date psd1 = axis.previousStandardDate(d1, unit);
    calendar.setTime(psd1);
    assertEquals(2006, calendar.get(Calendar.YEAR));
    assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH));
    assertEquals(25, calendar.get(Calendar.DATE));
    
    axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    Date psd2 = axis.previousStandardDate(d1, unit);
    calendar.setTime(psd2);
    assertEquals(2006, calendar.get(Calendar.YEAR));
    assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH));
    assertEquals(25, calendar.get(Calendar.DATE));

    axis.setTickMarkPosition(DateTickMarkPosition.END);
    Date psd3 = axis.previousStandardDate(d1, unit);
    calendar.setTime(psd3);
    assertEquals(2006, calendar.get(Calendar.YEAR));
    assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH));
    assertEquals(24, calendar.get(Calendar.DATE));
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:37,代码来源:DateAxisTests.java

示例13: testBug7686

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void testBug7686() throws SQLException {
    String tableName = "testBug7686";
    createTable(tableName, "(id1 int(10) unsigned NOT NULL, id2 DATETIME, field1 varchar(128) NOT NULL default '', PRIMARY KEY  (id1, id2))", "InnoDB;");

    this.stmt.executeUpdate("insert into " + tableName + " (id1, id2, field1) values (1, '2005-01-05 13:59:20', 'foo')");

    String sQuery = " SELECT * FROM " + tableName + " WHERE id1 = ? AND id2 = ?";
    this.pstmt = this.conn.prepareStatement(sQuery, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

    this.conn.setAutoCommit(false);
    this.pstmt.setInt(1, 1);
    GregorianCalendar cal = new GregorianCalendar();
    cal.clear();
    cal.set(2005, 00, 05, 13, 59, 20);

    Timestamp jan5before2pm = null;
    jan5before2pm = new java.sql.Timestamp(cal.getTimeInMillis());

    this.pstmt.setTimestamp(2, jan5before2pm);
    this.rs = this.pstmt.executeQuery();
    assertTrue(this.rs.next());
    this.rs.absolute(1);
    this.rs.updateString("field1", "bar");
    this.rs.updateRow();
    this.conn.commit();
    this.conn.setAutoCommit(true);

}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:29,代码来源:ResultSetRegressionTest.java

示例14: testPreviousStandardDateHour

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * A basic check for the testPreviousStandardDate() method when the
 * tick unit is 1 hour.
 */
public void testPreviousStandardDateHour() {
    MyDateAxis axis = new MyDateAxis("Hour");
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.set(2006, Calendar.AUGUST, 25, 12, 0);
    Date d1 = calendar.getTime();
    calendar.set(2007, Calendar.MAY, 20, 12, 0);
    Date d2 = calendar.getTime();
    axis.setRange(d1, d2);
    DateTickUnit unit = new DateTickUnit(DateTickUnit.HOUR, 1);
    axis.setTickUnit(unit);
    
    axis.setTickMarkPosition(DateTickMarkPosition.START);
    Date psd1 = axis.previousStandardDate(d1, unit);
    calendar.setTime(psd1);
    assertEquals(2006, calendar.get(Calendar.YEAR));
    assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH));
    assertEquals(25, calendar.get(Calendar.DATE));
    assertEquals(12, calendar.get(Calendar.HOUR_OF_DAY));
    
    axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    Date psd2 = axis.previousStandardDate(d1, unit);
    calendar.setTime(psd2);
    assertEquals(2006, calendar.get(Calendar.YEAR));
    assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH));
    assertEquals(25, calendar.get(Calendar.DATE));
    assertEquals(11, calendar.get(Calendar.HOUR_OF_DAY));

    axis.setTickMarkPosition(DateTickMarkPosition.END);
    Date psd3 = axis.previousStandardDate(d1, unit);
    calendar.setTime(psd3);
    assertEquals(2006, calendar.get(Calendar.YEAR));
    assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH));
    assertEquals(25, calendar.get(Calendar.DATE));
    assertEquals(11, calendar.get(Calendar.HOUR_OF_DAY));
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:40,代码来源:DateAxisTests.java

示例15: testPreviousStandardDateMinute

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * A basic check for the testPreviousStandardDate() method when the
 * tick unit is 1 minute.
 */
public void testPreviousStandardDateMinute() {
    MyDateAxis axis = new MyDateAxis("Minute");
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.set(2006, Calendar.AUGUST, 25, 12, 0, 10);
    Date d1 = calendar.getTime();
    calendar.set(2007, Calendar.MAY, 20, 12, 0, 10);
    Date d2 = calendar.getTime();
    axis.setRange(d1, d2);
    DateTickUnit unit = new DateTickUnit(DateTickUnit.MINUTE, 1);
    axis.setTickUnit(unit);
    
    axis.setTickMarkPosition(DateTickMarkPosition.START);
    Date psd1 = axis.previousStandardDate(d1, unit);
    calendar.setTime(psd1);
    assertEquals(2006, calendar.get(Calendar.YEAR));
    assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH));
    assertEquals(25, calendar.get(Calendar.DATE));
    assertEquals(12, calendar.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, calendar.get(Calendar.MINUTE));
    
    axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    Date psd2 = axis.previousStandardDate(d1, unit);
    calendar.setTime(psd2);
    assertEquals(2006, calendar.get(Calendar.YEAR));
    assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH));
    assertEquals(25, calendar.get(Calendar.DATE));
    assertEquals(11, calendar.get(Calendar.HOUR_OF_DAY));
    assertEquals(59, calendar.get(Calendar.MINUTE));

    axis.setTickMarkPosition(DateTickMarkPosition.END);
    Date psd3 = axis.previousStandardDate(d1, unit);
    calendar.setTime(psd3);
    assertEquals(2006, calendar.get(Calendar.YEAR));
    assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH));
    assertEquals(25, calendar.get(Calendar.DATE));
    assertEquals(11, calendar.get(Calendar.HOUR_OF_DAY));
    assertEquals(59, calendar.get(Calendar.MINUTE));
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:43,代码来源:DateAxisTests.java


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