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


Java Calendar.JANUARY属性代码示例

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


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

示例1: getDaysInMonth

public static int getDaysInMonth(int month, int year) {
    switch (month) {
        case Calendar.JANUARY:
        case Calendar.MARCH:
        case Calendar.MAY:
        case Calendar.JULY:
        case Calendar.AUGUST:
        case Calendar.OCTOBER:
        case Calendar.DECEMBER:
            return 31;
        case Calendar.APRIL:
        case Calendar.JUNE:
        case Calendar.SEPTEMBER:
        case Calendar.NOVEMBER:
            return 30;
        case Calendar.FEBRUARY:
            return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? 29 : 28;
        default:
            throw new IllegalArgumentException("Invalid Month");
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:CalendarUtils.java

示例2: getDaysInMonth

public static int getDaysInMonth(int month, int year) {
    switch (month) {
        case Calendar.JANUARY:
        case Calendar.MARCH:
        case Calendar.MAY:
        case Calendar.JULY:
        case Calendar.AUGUST:
        case Calendar.OCTOBER:
        case Calendar.DECEMBER:
            return 31;
        case Calendar.APRIL:
        case Calendar.JUNE:
        case Calendar.SEPTEMBER:
        case Calendar.NOVEMBER:
            return 30;
        case Calendar.FEBRUARY:
            return (year % 4 == 0) ? 29 : 28;
        default:
            throw new IllegalArgumentException("Invalid Month");
    }
}
 
开发者ID:MOLO17,项目名称:CustomizableCalendar,代码行数:21,代码来源:DateUtils.java

示例3: timestampToJson

@Test
public void timestampToJson() throws IOException {
    GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.MILLISECOND, 2000000000);
    calendar.add(Calendar.MILLISECOND, 2000000000);
    java.util.Date date = calendar.getTime();

    JsonNode converted = parse(converter.fromConnectData(TOPIC, Timestamp.SCHEMA, date));
    validateEnvelope(converted);
    assertEquals(parse("{ \"type\": \"int64\", \"optional\": false, \"name\": \"org.apache.kafka.connect.data.Timestamp\", \"version\": 1 }"),
            converted.get(JsonSchema.ENVELOPE_SCHEMA_FIELD_NAME));
    JsonNode payload = converted.get(JsonSchema.ENVELOPE_PAYLOAD_FIELD_NAME);
    assertTrue(payload.isLong());
    assertEquals(4000000000L, payload.longValue());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:16,代码来源:JsonConverterTest.java

示例4: getDaysInMonth

/**
 * @param month 从0开始
 * @param year  年份
 * @return days
 */
public static int getDaysInMonth(int month, int year) {
    switch (month) {
        case Calendar.JANUARY:
        case Calendar.MARCH:
        case Calendar.MAY:
        case Calendar.JULY:
        case Calendar.AUGUST:
        case Calendar.OCTOBER:
        case Calendar.DECEMBER:
            return 31;
        case Calendar.APRIL:
        case Calendar.JUNE:
        case Calendar.SEPTEMBER:
        case Calendar.NOVEMBER:
            return 30;
        case Calendar.FEBRUARY:
            return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? 29 : 28;
        default:
            throw new IllegalArgumentException("Invalid Month");
    }
}
 
开发者ID:sieml,项目名称:CalendarCheck,代码行数:26,代码来源:CalendarUtils.java

示例5: getElapsedMonths

/**
 * Returns the time elapsed so far this month and the last numMonths months in milliseconds.
 *
 * @param numMonths Additional number of months prior to the current month to calculate.
 * @return Time elapsed this month and the last numMonths months in milliseconds.
 */
public long getElapsedMonths(int numMonths) {
    // Today + rest of this month
    long elapsed = getElapsedMonth();

    // Previous numMonths months
    int month = calendar.get(Calendar.MONTH);
    int year = calendar.get(Calendar.YEAR);
    for (int i = 0; i < numMonths; i++) {
        month--;

        if (month < Calendar.JANUARY) {
            month = Calendar.DECEMBER;
            year--;
        }

        elapsed += getDaysInMonth(year, month) * MS_PER_DAY;
    }

    return elapsed;
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:26,代码来源:CalendarUtil.java

示例6: main

public static void main(String[] args) throws ReportingAPISDKException {
    // Instantiating ReportingAPI instance is always the first step. Use this instance to access
    // all kinds of reports.
    ReportingAPI reportingApi = new ReportingAPI(HOSTNAME, API_VERSION, AUDIT_ADMIN_USERNAME,
            PASSWORD,
            UNIQUE_ID, CLIENT_VERSION,
            CLIENT_NICKNAME);
    // Get audit report through ReportingAPI instance. Here is an example of getting account
    // activity report.
    Calendar startTime = new GregorianCalendar(2016, Calendar.JANUARY, 1);
    UserReportPage<AuditAccountActivityReportUserEntry> userAccountReport = reportingApi
            .getAuditReports().getAccountActivityReport()
            .getReportOnUser(USER_TO_AUDIT, startTime.getTimeInMillis(),
                             System.currentTimeMillis(), null, null)
            .getResponseType();
    // The content of the report is encapsulated as Java object. They can be processed in
    // programmatic ways.
    for (AuditAccountActivityReportUserEntry userEntry : userAccountReport.getUsers()) {
        System.out.println(userEntry.getUser());
    }
    // Get admin report through ReportingAPI instance. Here is an example of getting admin user
    // last access report.
    UserReportPage<AdminUserLastAccessReportUserEntry> lastAccessReportFirstPage = reportingApi
            .getAdminReports().getUserLastAccessReport()
            .getSystemScopeReport(MAX_RESULTS, null, null)
            .getResponseType();
    // If the report is not finished, get the next page of the report with page token.
    String pageToken = lastAccessReportFirstPage.getPageToken();
    UserReportPage<AdminUserLastAccessReportUserEntry> lastAccessReportSecondPage = reportingApi
            .getAdminReports().getUserLastAccessReport()
            .getReportWithPageToken(pageToken, MAX_RESULTS, null)
            .getResponseType();
    System.out.println(lastAccessReportSecondPage);
}
 
开发者ID:HitachiDataSystems,项目名称:aw-reportingapi,代码行数:34,代码来源:Example.java

示例7: Test4278609

public void Test4278609() {
    SimpleTimeZone tz = new SimpleTimeZone(0, "MyTimeZone",
                           /* DST start day: August, 1, 0:00 */
                           Calendar.AUGUST, 1, 0, 0,
                           /* DST end day: January, 1, 0:00 (wall-clock)*/
                           Calendar.JANUARY, 1, 0, 0,
                           60 * 60 * 1000);

    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

    // setting a date using GMT zone just after the end rule of tz zone
    cal.clear();
    cal.set(Calendar.ERA, GregorianCalendar.AD);
    cal.set(1998, Calendar.DECEMBER, 31, 23, 01, 00);

    Date date = cal.getTime();

    int millis = cal.get(Calendar.HOUR_OF_DAY) * 3600000
                 + cal.get(Calendar.MINUTE) * 60000
                 + cal.get(Calendar.SECOND) * 1000
                 + cal.get(Calendar.MILLISECOND);
    /* we must use standard local time */
    millis += tz.getRawOffset();

    int offset = tz.getOffset(cal.get(Calendar.ERA),
                              cal.get(Calendar.YEAR),
                              cal.get(Calendar.MONTH),
                              cal.get(Calendar.DATE),
                              cal.get(Calendar.DAY_OF_WEEK),
                              millis);

    if (offset != 0) {
        SimpleDateFormat format = new SimpleDateFormat("dd MMM HH:mm:ss zzz",
                                                       Locale.US);
        format.setTimeZone(tz);
        errln("Wrong DST transition: " + tz
              + "\na date just after DST = " + format.format(date)
              + "\ngetOffset = " + offset);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:TransitionTest.java

示例8: getSeason

/**
 * 
 * 1 第一季度 2 第二季度 3 第三季度 4 第四季度
 * 
 * @param date
 * @return
 */
public static int getSeason(Date date) {

	int season = 0;

	Calendar c = Calendar.getInstance();
	c.setTime(date);
	int month = c.get(Calendar.MONTH);
	switch (month) {
	case Calendar.JANUARY:
	case Calendar.FEBRUARY:
	case Calendar.MARCH:
		season = 1;
		break;
	case Calendar.APRIL:
	case Calendar.MAY:
	case Calendar.JUNE:
		season = 2;
		break;
	case Calendar.JULY:
	case Calendar.AUGUST:
	case Calendar.SEPTEMBER:
		season = 3;
		break;
	case Calendar.OCTOBER:
	case Calendar.NOVEMBER:
	case Calendar.DECEMBER:
		season = 4;
		break;
	default:
		break;
	}
	return season;
}
 
开发者ID:babymm,项目名称:mumu,代码行数:40,代码来源:DateUtils.java

示例9: main

/**
 * Before the fix, JDK8 prints: {@code
 * <record>
 *   <date>3913-11-18T17:35:40</date>
 *   <millis>1384792540403</millis>
 *   <sequence>0</sequence>
 *   <level>INFO</level>
 *   <thread>1</thread>
 *   <message>test</message>
 * </record>
 * }
 * After the fix, it should print: {@code
 * <record>
 *   <date>2013-11-18T17:35:40</date>
 *   <millis>1384792696519</millis>
 *   <sequence>0</sequence>
 *   <level>INFO</level>
 *   <thread>1</thread>
 *   <message>test</message>
 * </record>
 * }
 * @param args the command line arguments
 */
public static void main(String[] args) {
    Locale locale = Locale.getDefault();
    try {
        Locale.setDefault(Locale.ENGLISH);

        final GregorianCalendar cal1 = new GregorianCalendar();
        final int year1 = cal1.get(Calendar.YEAR);

        LogRecord record = new LogRecord(Level.INFO, "test");
        XMLFormatter formatter = new XMLFormatter();
        final String formatted = formatter.format(record);
        System.out.println(formatted);

        final GregorianCalendar cal2 = new GregorianCalendar();
        final int year2 = cal2.get(Calendar.YEAR);
        if (year2 < 1900) {
            throw new Error("Invalid system year: " + year2);
        }

        StringBuilder buf2 = new StringBuilder()
                .append("<date>").append(year2).append("-");
        if (!formatted.contains(buf2.toString())) {
            StringBuilder buf1 = new StringBuilder()
                    .append("<date>").append(year1).append("-");
            if (formatted.contains(buf1)
                    && year2 == year1 + 1
                    && cal2.get(Calendar.MONTH) == Calendar.JANUARY
                    && cal2.get(Calendar.DAY_OF_MONTH) == 1) {
                // Oh! The year just switched in the midst of the test...
                System.out.println("Happy new year!");
            } else {
                throw new Error("Expected year " + year2
                        + " not found in log:\n" + formatted);
            }
        }
    } finally {
        Locale.setDefault(locale);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:62,代码来源:XMLFormatterDate.java

示例10: getSeason

/**
 *
 * 1 第一季度 2 第二季度 3 第三季度 4 第四季度
 *
 * @param date
 * @return
 */
public static int getSeason(Date date) {

	int season = 0;

	Calendar c = Calendar.getInstance();
	c.setTime(date);
	int month = c.get(Calendar.MONTH);
	switch (month) {
	case Calendar.JANUARY:
	case Calendar.FEBRUARY:
	case Calendar.MARCH:
		season = 1;
		break;
	case Calendar.APRIL:
	case Calendar.MAY:
	case Calendar.JUNE:
		season = 2;
		break;
	case Calendar.JULY:
	case Calendar.AUGUST:
	case Calendar.SEPTEMBER:
		season = 3;
		break;
	case Calendar.OCTOBER:
	case Calendar.NOVEMBER:
	case Calendar.DECEMBER:
		season = 4;
		break;
	default:
		break;
	}
	return season;
}
 
开发者ID:xubinux,项目名称:xbin-store,代码行数:40,代码来源:DateUtils.java

示例11: getDaysInMonth

/**
 * 获取月份的天数
 *
 * @param mills
 * @return
 */
public static int getDaysInMonth(long mills) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(mills);

    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);

    switch (month) {
        case Calendar.JANUARY:
        case Calendar.MARCH:
        case Calendar.MAY:
        case Calendar.JULY:
        case Calendar.AUGUST:
        case Calendar.OCTOBER:
        case Calendar.DECEMBER:
            return 31;
        case Calendar.APRIL:
        case Calendar.JUNE:
        case Calendar.SEPTEMBER:
        case Calendar.NOVEMBER:
            return 30;
        case Calendar.FEBRUARY:
            return (year % 4 == 0) ? 29 : 28;
        default:
            throw new IllegalArgumentException("Invalid Month");
    }
}
 
开发者ID:lzmlsfe,项目名称:19porn,代码行数:33,代码来源:Kits.java

示例12: getElapsedYear

/**
 * Returns the time elapsed so far this year in milliseconds.
 *
 * @return Time elapsed this year in milliseconds.
 */
public long getElapsedYear() {
    // Today + rest of this month + previous months until January
    long elapsed = getElapsedMonth();

    int month = calendar.get(Calendar.MONTH) - 1;
    int year = calendar.get(Calendar.YEAR);
    while (month > Calendar.JANUARY) {
        elapsed += getDaysInMonth(year, month) * MS_PER_DAY;

        month--;
    }

    return elapsed;
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:19,代码来源:CalendarUtil.java

示例13: parse

public static long parse(String timeString)
        throws IllegalArgumentException {

    int date = 1;
    int month = Calendar.JANUARY;
    int year = 1970;
    TimeOfDay timeOfDay;

    Matcher rfcMatcher = HTTP_DATE_RFC_PATTERN.matcher(timeString);
    if (rfcMatcher.find()) {
        date = getDate(rfcMatcher.group(1));
        month = getMonth(rfcMatcher.group(2));
        year = getYear(rfcMatcher.group(3));
        timeOfDay = getTime(rfcMatcher.group(4));
    } else {
        Matcher ansicMatcher = HTTP_DATE_ANSIC_PATTERN.matcher(timeString);
        if (ansicMatcher.find()) {
            month = getMonth(ansicMatcher.group(1));
            date = getDate(ansicMatcher.group(2));
            timeOfDay = getTime(ansicMatcher.group(3));
            year = getYear(ansicMatcher.group(4));
        } else {
            throw new IllegalArgumentException();
        }
    }

    // FIXME: Y2038 BUG!
    if (year >= 2038) {
        year = 2038;
        month = Calendar.JANUARY;
        date = 1;
    }

    Time time = new Time(Time.TIMEZONE_UTC);
    time.set(timeOfDay.second, timeOfDay.minute, timeOfDay.hour, date,
            month, year);
    return time.toMillis(false /* use isDst */);
}
 
开发者ID:snoozinsquatch,项目名称:unity-obb-downloader,代码行数:38,代码来源:HttpDateTime.java

示例14: setMonth

/**
 * Set the month member
 * @param m String to set.
 * @throws IllegalArgumentException if m is not a valid month
 */
public void setMonth(String m) throws IllegalArgumentException {
    sipMonth = m;
    if (sipMonth.compareToIgnoreCase(JAN) == 0) {
        month = Calendar.JANUARY;
    } else if (sipMonth.compareToIgnoreCase(FEB) == 0) {
        month = Calendar.FEBRUARY;
    } else if (sipMonth.compareToIgnoreCase(MAR) == 0) {
        month = Calendar.MARCH;
    } else if (sipMonth.compareToIgnoreCase(APR) == 0) {
        month = Calendar.APRIL;
    } else if (sipMonth.compareToIgnoreCase(MAY) == 0) {
        month = Calendar.MAY;
    } else if (sipMonth.compareToIgnoreCase(JUN) == 0) {
        month = Calendar.JUNE;
    } else if (sipMonth.compareToIgnoreCase(JUL) == 0) {
        month = Calendar.JULY;
    } else if (sipMonth.compareToIgnoreCase(AUG) == 0) {
        month = Calendar.AUGUST;
    } else if (sipMonth.compareToIgnoreCase(SEP) == 0) {
        month = Calendar.SEPTEMBER;
    } else if (sipMonth.compareToIgnoreCase(OCT) == 0) {
        month = Calendar.OCTOBER;
    } else if (sipMonth.compareToIgnoreCase(NOV) == 0) {
        month = Calendar.NOVEMBER;
    } else if (sipMonth.compareToIgnoreCase(DEC) == 0) {
        month = Calendar.DECEMBER;
    } else {
        throw new IllegalArgumentException("Illegal Month :" + m);
    }
}
 
开发者ID:YunlongYang,项目名称:LightSIP,代码行数:35,代码来源:SIPDate.java

示例15: onMonthChanged

@Override
public void onMonthChanged(@NonNull CalendarView calendarView, @IntRange(from = Calendar.JANUARY, to = Calendar.DECEMBER) int month) {
	Log.d(TAG, "Calendar scrolled to month: " + month);
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:4,代码来源:DatePickerFragment.java


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