本文整理汇总了Java中java.util.GregorianCalendar.clear方法的典型用法代码示例。如果您正苦于以下问题:Java GregorianCalendar.clear方法的具体用法?Java GregorianCalendar.clear怎么用?Java GregorianCalendar.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.GregorianCalendar
的用法示例。
在下文中一共展示了GregorianCalendar.clear方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dateValueToDate
import java.util.GregorianCalendar; //导入方法依赖的package包/类
static Date dateValueToDate(DateValue dvUtc) {
GregorianCalendar c = new GregorianCalendar(TimeUtils.utcTimezone());
c.clear();
if (dvUtc instanceof TimeValue) {
TimeValue tvUtc = (TimeValue) dvUtc;
c.set(dvUtc.year(),
dvUtc.month() - 1, // java.util's dates are zero-indexed
dvUtc.day(),
tvUtc.hour(),
tvUtc.minute(),
tvUtc.second());
} else {
c.set(dvUtc.year(),
dvUtc.month() - 1, // java.util's dates are zero-indexed
dvUtc.day(),
0,
0,
0);
}
return c.getTime();
}
示例2: main
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static void main(String args[]) {
GregorianCalendar cal = new GregorianCalendar();
cal.clear();
cal.set(YEAR, 2003);
long t = cal.getTime().getTime();
// For the time calculation, the MONTH and DAY_OF_MONTH fields
// (with the default values) have been used for determining
// the date. However, both the MONTH and DAY_OF_MONTH fields
// should be kept UNSET after the time calculation.
if (cal.isSet(MONTH) || cal.isSet(DAY_OF_MONTH)) {
throw new RuntimeException("After getTime(): MONTH field=" + cal.isSet(MONTH)
+ ", DAY_OF_MONTH field=" + cal.isSet(DAY_OF_MONTH));
}
// After calling get() for any field, all field values are
// recalculated and their field states are set to
// COMPUTED. isSet() must return true.
int y = cal.get(YEAR);
if (!(cal.isSet(MONTH) && cal.isSet(DAY_OF_MONTH))) {
throw new RuntimeException("After get(): MONTH field=" + cal.isSet(MONTH)
+ ", DAY_OF_MONTH field=" + cal.isSet(DAY_OF_MONTH));
}
}
示例3: main
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static void main(String[] args) {
for (int l = 0; l < locales.length; l++) {
Locale loc = locales[l];
for (int i = 0; i < offsets.length; i++) {
test(loc, offsets[i][0], offsets[i][1]);
}
}
// The test case in the bug report.
GregorianCalendar cal = new GregorianCalendar();
cal.setLenient(false);
cal.setGregorianChange(new Date(Long.MIN_VALUE));
cal.clear();
cal.set(ZONE_OFFSET, 0);
cal.set(DST_OFFSET, 0);
cal.set(ERA, AD);
cal.set(2004, FEBRUARY, 3, 0, 0, 0);
cal.set(MILLISECOND, 0);
// The following line should not throw an IllegalArgumentException.
cal.getTime();
}
示例4: Test4031502
import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void Test4031502() {
// This bug actually occurs on Windows NT as well, and doesn't
// require the host zone to be set; it can be set in Java.
String[] ids = TimeZone.getAvailableIDs();
boolean bad = false;
for (int i = 0; i < ids.length; ++i) {
TimeZone zone = TimeZone.getTimeZone(ids[i]);
GregorianCalendar cal = new GregorianCalendar(zone);
cal.clear();
cal.set(1900, 15, 5, 5, 8, 13);
if (cal.get(HOUR) != 5) {
logln(zone.getID() + " "
+ //zone.useDaylightTime() + " "
+ cal.get(DST_OFFSET) / (60 * 60 * 1000) + " "
+ zone.getRawOffset() / (60 * 60 * 1000)
+ ": HOUR = " + cal.get(HOUR));
bad = true;
}
}
if (bad) {
errln("TimeZone problems with GC");
}
}
示例5: Test4125881
import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
* Check isLeapYear for BC years.
*/
public void Test4125881() {
Locale locale = Locale.getDefault();
if (!TestUtils.usesGregorianCalendar(locale)) {
logln("Skipping this test because locale is " + locale);
return;
}
GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance();
DateFormat fmt = new SimpleDateFormat("MMMM d, yyyy G");
cal.clear();
for (int y = -20; y <= 10; ++y) {
cal.set(ERA, y < 1 ? GregorianCalendar.BC : GregorianCalendar.AD);
cal.set(YEAR, y < 1 ? 1 - y : y);
logln(y + " = " + fmt.format(cal.getTime()) + " "
+ cal.isLeapYear(y));
if (cal.isLeapYear(y) != ((y + 40) % 4 == 0)) {
errln("Leap years broken");
}
}
}
示例6: Test4125892
import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
* Prove that GregorianCalendar is proleptic (it used to cut off
* at 45 BC, and not have leap years before then).
*/
public void Test4125892() {
Locale locale = Locale.getDefault();
if (!TestUtils.usesGregorianCalendar(locale)) {
logln("Skipping this test because locale is " + locale);
return;
}
GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance();
DateFormat fmt = new SimpleDateFormat("MMMM d, yyyy G");
cal.clear();
cal.set(ERA, GregorianCalendar.BC);
cal.set(YEAR, 81); // 81 BC is a leap year (proleptically)
cal.set(MONTH, FEBRUARY);
cal.set(DATE, 28);
cal.add(DATE, 1);
if (cal.get(DATE) != 29
|| !cal.isLeapYear(-80)) { // -80 == 81 BC
errln("Calendar not proleptic");
}
}
示例7: getCalendar
import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
* neues Calendar mit Datum und Zeit undefiniert.
*/
private static GregorianCalendar getCalendar() {
GregorianCalendar cal = new GregorianCalendar();
cal.setLenient(false);
cal.clear();
return cal;
}
示例8: 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);
}
示例9: setupBlockedTimeSlots
import java.util.GregorianCalendar; //导入方法依赖的package包/类
private void setupBlockedTimeSlots() {
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.set(java.util.Calendar.HOUR_OF_DAY, 0); // ! clear would not reset the hour of day !
cal.clear(java.util.Calendar.MINUTE);
cal.clear(java.util.Calendar.SECOND);
cal.clear(java.util.Calendar.MILLISECOND);
GregorianCalendar bcal = new GregorianCalendar(UI.getCurrent().getLocale());
bcal.clear();
long start = bcal.getTimeInMillis();
bcal.add(java.util.Calendar.HOUR, 7);
bcal.add(java.util.Calendar.MINUTE, 30);
long end = bcal.getTimeInMillis();
calendar.addTimeBlock(start, end, "my-blocky-style");
cal.add(java.util.Calendar.DAY_OF_WEEK, 1);
bcal.clear();
bcal.add(java.util.Calendar.HOUR, 14);
bcal.add(java.util.Calendar.MINUTE, 30);
start = bcal.getTimeInMillis();
bcal.add(java.util.Calendar.MINUTE, 60);
end = bcal.getTimeInMillis();
calendar.addTimeBlock(start, end);
}
示例10: 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);
}
}
示例11: getGregorianDate
import java.util.GregorianCalendar; //导入方法依赖的package包/类
static Date getGregorianDate(int year, int month, int dayOfMonth) {
GregorianCalendar g = new GregorianCalendar();
// Make g a pure Gregorian calendar
g.setGregorianChange(new Date(Long.MIN_VALUE));
g.clear();
g.set(year, month, dayOfMonth);
return g.getTime();
}
示例12: durationAssertEquals
import java.util.GregorianCalendar; //导入方法依赖的package包/类
private void durationAssertEquals(Duration duration, QName xmlSchemaType, boolean isPositive, int years, int months, int days, int hours, int minutes,
int seconds, long milliseconds, String lexical) {
final TimeZone GMT = TimeZone.getTimeZone("GMT");
final GregorianCalendar EPOCH = new GregorianCalendar(GMT);
EPOCH.clear();
if (DEBUG) {
System.out.println("Testing Duration: " + duration.toString());
}
// sign
if (DEBUG) {
boolean actual = (duration.getSign() == 1) ? true : false;
System.out.println("sign:");
System.out.println(" expected: \"" + isPositive + "\"");
System.out.println(" actual: \"" + actual + "\"");
}
if (DEBUG) {
System.out.println("years:");
System.out.println(" expected: \"" + years + "\"");
System.out.println(" actual: \"" + duration.getYears() + "\"");
}
if (DEBUG) {
System.out.println("months:");
System.out.println(" expected: \"" + months + "\"");
System.out.println(" actual: \"" + duration.getMonths() + "\"");
}
if (DEBUG) {
System.out.println("days:");
System.out.println(" expected: \"" + days + "\"");
System.out.println(" actual: \"" + duration.getDays() + "\"");
}
if (DEBUG) {
System.out.println("hours:");
System.out.println(" expected: \"" + hours + "\"");
System.out.println(" actual: \"" + duration.getHours() + "\"");
}
if (DEBUG) {
System.out.println("minutes:");
System.out.println(" expected: \"" + minutes + "\"");
System.out.println(" actual: \"" + duration.getMinutes() + "\"");
}
if (DEBUG) {
System.out.println("seconds:");
System.out.println(" expected: \"" + seconds + "\"");
System.out.println(" actual: \"" + duration.getSeconds() + "\"");
}
if (DEBUG) {
System.out.println("milliseconds:");
System.out.println(" expected: \"" + milliseconds + "\"");
System.out.println(" actual: \"" + duration.getTimeInMillis(EPOCH) + "\"");
}
if (DEBUG) {
System.out.println("lexical:");
System.out.println(" expected: \"" + lexical + "\"");
System.out.println(" actual: \"" + duration.toString() + "\"");
}
}