本文整理匯總了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");
}
}
示例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");
}
}
示例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());
}
示例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");
}
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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");
}
}
示例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;
}
示例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 */);
}
示例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);
}
}
示例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);
}