本文整理匯總了Java中java.util.GregorianCalendar.isLeapYear方法的典型用法代碼示例。如果您正苦於以下問題:Java GregorianCalendar.isLeapYear方法的具體用法?Java GregorianCalendar.isLeapYear怎麽用?Java GregorianCalendar.isLeapYear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.GregorianCalendar
的用法示例。
在下文中一共展示了GregorianCalendar.isLeapYear方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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");
}
}
}
示例2: 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");
}
}
示例3: checkBirthday
import java.util.GregorianCalendar; //導入方法依賴的package包/類
private void checkBirthday(int year, int month, int day)
{
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement(QUERY))
{
statement.setString(1, "%-" + getNum(month + 1) + "-" + getNum(day));
try (ResultSet rset = statement.executeQuery())
{
while (rset.next())
{
final int playerId = rset.getInt("charId");
final Calendar createDate = Calendar.getInstance();
createDate.setTime(rset.getDate("createDate"));
final int age = year - createDate.get(Calendar.YEAR);
if (age <= 0)
{
continue;
}
String text = Config.ALT_BIRTHDAY_MAIL_TEXT;
if (text.contains("$c1"))
{
text = text.replace("$c1", CharNameTable.getInstance().getNameById(playerId));
}
if (text.contains("$s1"))
{
text = text.replace("$s1", String.valueOf(age));
}
final Message msg = new Message(playerId, Config.ALT_BIRTHDAY_MAIL_SUBJECT, text, MailType.BIRTHDAY);
final Mail attachments = msg.createAttachments();
attachments.addItem("Birthday", Config.ALT_BIRTHDAY_GIFT, 1, null, null);
MailManager.getInstance().sendMessage(msg);
_count++;
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, "Error checking birthdays. ", e);
}
// If character birthday is 29-Feb and year isn't leap, send gift on 28-feb
final GregorianCalendar calendar = new GregorianCalendar();
if ((month == Calendar.FEBRUARY) && (day == 28) && !calendar.isLeapYear(_today.get(Calendar.YEAR)))
{
checkBirthday(year, Calendar.FEBRUARY, 29);
}
}
示例4: Test4149677
import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
* Reported bug is that a GregorianCalendar with a cutover of Date(Long.MAX_VALUE)
* doesn't behave as a pure Julian calendar.
* CANNOT REPRODUCE THIS BUG
*/
public void Test4149677() {
TimeZone[] zones = {TimeZone.getTimeZone("GMT"),
TimeZone.getTimeZone("PST"),
TimeZone.getTimeZone("EAT")};
for (int i = 0; i < zones.length; ++i) {
GregorianCalendar calendar = new GregorianCalendar(zones[i]);
// Make sure extreme values don't wrap around
calendar.setTime(new Date(Long.MIN_VALUE));
if (calendar.get(ERA) != GregorianCalendar.BC) {
errln("Fail: Date(Long.MIN_VALUE) has an AD year in " + zones[i]);
}
calendar.setTime(new Date(Long.MAX_VALUE));
if (calendar.get(ERA) != GregorianCalendar.AD) {
errln("Fail: Date(Long.MAX_VALUE) has a BC year in " + zones[i]);
}
calendar.setGregorianChange(new Date(Long.MAX_VALUE));
// to obtain a pure Julian calendar
boolean is100Leap = calendar.isLeapYear(100);
if (!is100Leap) {
errln("test failed with zone " + zones[i].getID());
errln(" cutover date is Date(Long.MAX_VALUE)");
errln(" isLeapYear(100) returns: " + is100Leap);
}
}
}
示例5: completeDate
import java.util.GregorianCalendar; //導入方法依賴的package包/類
private String completeDate(GregorianCalendar gc, boolean bLongInfo)
{
GregorianCalendar calendar = (GregorianCalendar)gc.clone();
String csDate = "00000000";
String csDayOfWeek = "0";
String csDaysInMonth = "00";
String csDayOfYear = "000";
String csDaysToEndYear = "000";
String csDaysInYear = "000";
String csWeekOfYear = "00";
String csDayEaster = "000";
String csFlagHoliday = " ";
String csLeapYear = "0";
calendar.setFirstDayOfWeek(GregorianCalendar.MONDAY);
calendar.setMinimalDaysInFirstWeek(4);
Format formatter = new SimpleDateFormat("yyyyMMdd");
csDate = formatter.format(calendar.getTime());
int dayOfWeek = calendar.get(GregorianCalendar.DAY_OF_WEEK);
if (dayOfWeek == 1)
{
csDayOfWeek = "7";
}
else
{
csDayOfWeek = String.valueOf(dayOfWeek - 1) ;
}
csDaysInMonth = String.valueOf(calendar.getActualMaximum(GregorianCalendar.DAY_OF_MONTH));
csWeekOfYear = StringUtil.leftPad(String.valueOf(calendar.get(GregorianCalendar.WEEK_OF_YEAR)), 2, '0');
int dayOfYear = calendar.get(GregorianCalendar.DAY_OF_YEAR);
calendar.set(GregorianCalendar.MONTH, 11);
calendar.set(GregorianCalendar.DAY_OF_MONTH, 31);
int daysInYear = calendar.get(GregorianCalendar.DAY_OF_YEAR);
csDayOfYear = StringUtil.leftPad(String.valueOf(dayOfYear), 3, '0');
csDaysToEndYear = StringUtil.leftPad(String.valueOf(daysInYear - dayOfYear), 3, '0');
csDaysInYear = StringUtil.leftPad(String.valueOf(daysInYear), 3, '0');
GregorianCalendar easterCalendar = findDateEaster(calendar.get(GregorianCalendar.YEAR));
easterCalendar.set(GregorianCalendar.HOUR, 0);
csDayEaster = StringUtil.leftPad(String.valueOf(easterCalendar.get(GregorianCalendar.DAY_OF_YEAR)), 3, '0');
//int diffEasterDays = elapsedTime(easterCalendar, calendar, GregorianCalendar.DATE);
long diffMillis = gc.getTimeInMillis() - easterCalendar.getTimeInMillis();
long diffEasterDays = diffMillis/(24*60*60*1000);
if (csDate.substring(4).equals("0101") ||
csDate.substring(4).equals("0102") ||
csDate.substring(4).equals("0801") ||
csDate.substring(4).equals("1225") ||
csDate.substring(4).equals("1226") ||
csDayEaster.equals(csDayOfYear) ||
diffEasterDays == 1 || // lundi de P�ques
diffEasterDays == 39 || // Ascension
diffEasterDays == 50) // Pentec�te
{
csFlagHoliday = "F";
}
if (calendar.isLeapYear(calendar.get(GregorianCalendar.YEAR)))
{
csLeapYear = "9";
}
if (bLongInfo)
{
return csDate + csDayOfWeek + csDaysInMonth + csDayOfYear + csDaysToEndYear + csDaysInYear + csWeekOfYear + csDayEaster + csFlagHoliday;
}
else
{
String csTarif = csDayOfWeek;
if (csFlagHoliday.equals("F"))
csTarif = "7";
return csDate.substring(2) + csDayOfYear + csLeapYear + csTarif + csDayOfWeek + csWeekOfYear;
}
}
示例6: printDayWeek
import java.util.GregorianCalendar; //導入方法依賴的package包/類
private void printDayWeek(JPanel panel, GridAndParams res, int weekDay) {
final GregorianCalendar gc = new GregorianCalendar();
panel.removeAll();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
for (Date dd : res.getTimes()) {
gc.setTime(dd);
int ii = gc.get(GregorianCalendar.DAY_OF_WEEK) - 1;
if (ii < 1) {
ii = 7;
}
gc.setTime(this.firstWeekDay);
gc.add(GregorianCalendar.DAY_OF_WEEK, ii - 1);
final GregorianCalendar gc_client = new GregorianCalendar();
final GregorianCalendar gc_now = new GregorianCalendar();
gc_client.setTime(dd);
gc_now.setTime(new Date());
// проверим не отлистал ли пользователь слишком далеко, куда уже нельзя
boolean f = true;
int per = 0;
if (gc_client.get(GregorianCalendar.DAY_OF_YEAR) - gc_now
.get(GregorianCalendar.DAY_OF_YEAR)
> 0) {
per = gc_client.get(GregorianCalendar.DAY_OF_YEAR) - gc_now
.get(GregorianCalendar.DAY_OF_YEAR);
} else {
per = gc_client.get(GregorianCalendar.DAY_OF_YEAR) + (
gc_now.isLeapYear(gc_now.get(GregorianCalendar.YEAR)) ? 365
: 366 - gc_now.get(GregorianCalendar.DAY_OF_YEAR));
}
if (per > res.getAdvanceLimitPeriod() && res.getAdvanceLimitPeriod() != 0) {
f = false;
}
if (ii == weekDay && f && gc.getTime().after(gc_now.getTime())) {
panel.add(new QAvancePanel(new IAdviceEvent() {
@Override
public void eventPerformed(Date date) {
if (clockBack.isActive()) {
clockBack.stop();
}
// ставим предварительного кастомера
result = NetCommander
.standInServiceAdvance(netProperty, service.getId(), date,
advancedCustomer,
inputData, comments);
// закрываем диалог выбора предварительного выбора времени
setVisible(false);
}
}, dd, true));
}
}
if (panel.getComponentCount() == 0) {
panel.setLayout(new GridLayout(1, 1));
panel.add(new JLabel(new ImageIcon(
Uses.loadImage(this, "/ru/apertum/qsystem/client/forms/resources/noActive.png",
null)),
JLabel.CENTER));
}
}