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


Java GregorianCalendar.get方法代码示例

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


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

示例1: Test4100311

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void Test4100311() {
    Locale locale = Locale.getDefault();
    if (!TestUtils.usesGregorianCalendar(locale)) {
        logln("Skipping this test because locale is " + locale);
        return;
    }

    GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance();
    cal.set(YEAR, 1997);
    cal.set(DAY_OF_YEAR, 1);
    Date d = cal.getTime();             // Should be Jan 1
    logln(d.toString());
    if (cal.get(DAY_OF_YEAR) != 1) {
        errln("Fail: DAY_OF_YEAR not set");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:CalendarRegression.java

示例2: getBeijingNowTimeString

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static String getBeijingNowTimeString(String format) {
    TimeZone timezone = TimeZone.getTimeZone("Asia/Shanghai");

    Date date = new Date(currentTimeMillis());
    SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.getDefault());
    formatter.setTimeZone(timezone);

    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTimeZone(timezone);
    String prefix = gregorianCalendar.get(Calendar.AM_PM) == Calendar.AM ? "上午" : "下午";

    return prefix + formatter.format(date);
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:14,代码来源:TimeUtil.java

示例3: setProdosDate

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * Set a ProDOS date into the buffer.
 */
public static void setProdosDate(byte[] buffer, int offset, Date date) {
	int day = 0;
	int month = 0;
	int year = 0;
	int minute = 0;
	int hour = 0;
	if (date != null) {
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(date);
		day = gc.get(Calendar.DAY_OF_MONTH);
		month = gc.get(Calendar.MONTH) + 1;
		year = gc.get(Calendar.YEAR);
		minute = gc.get(Calendar.MINUTE);
		hour = gc.get(Calendar.HOUR_OF_DAY);
		if (year >= 2000) {
			year -= 2000;
		} else {
			year -= 1900;
		}
	}
	int ymd = ((year & 0x7f) << 9) | ((month & 0xf) << 5) | (day & 0x1f);
	int hm = ((hour & 0x1f) << 8) | (minute & 0x3f);
	setWordValue(buffer, offset, ymd);
	setWordValue(buffer, offset+2, hm);
}
 
开发者ID:AppleCommander,项目名称:AppleCommander,代码行数:29,代码来源:AppleUtil.java

示例4: Test4145983

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * Maximum value for YEAR field wrong.
 */
public void Test4145983() {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
    Date[] DATES = {new Date(Long.MAX_VALUE), new Date(Long.MIN_VALUE)};
    for (int i = 0; i < DATES.length; ++i) {
        calendar.setTime(DATES[i]);
        int year = calendar.get(YEAR);
        int maxYear = calendar.getMaximum(YEAR);
        if (year > maxYear) {
            errln("Failed for " + DATES[i].getTime() + " ms: year="
                    + year + ", maxYear=" + maxYear);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:CalendarRegression.java

示例5: getNthWeekdayBeforeDate

import java.util.GregorianCalendar; //导入方法依赖的package包/类
private static Date getNthWeekdayBeforeDate(Date date, Weekday weekday, int n) {
	GregorianCalendar cal = new GregorianCalendar();
	cal.setTime(date);
	int delta = getWeekdayNum(weekday) - cal.get(GregorianCalendar.DAY_OF_WEEK); // sunday ..1, monday ..2, ...
	if (delta > 0) {
		delta -= 7;
	}
	cal.add(Calendar.DATE, delta - (n - 1) * 7);
	return cal.getTime();
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:11,代码来源:DateCalc.java

示例6: makeDateString

import java.util.GregorianCalendar; //导入方法依赖的package包/类
private CharSequence makeDateString(Concert concert) {
    int currentYear = new GregorianCalendar().get(Calendar.YEAR);

    GregorianCalendar concertCalendar = new GregorianCalendar();
    concertCalendar.setTime(concert.getDate());
    int concertYear = concertCalendar.get(Calendar.YEAR);

    String dateFormatString =
            currentYear == concertYear ? thisYearDateFormat : anotherYearDateFormat;

    return DateFormat.format(dateFormatString, concert.getDate());
}
 
开发者ID:andreybgm,项目名称:gigreminder,代码行数:13,代码来源:ListViewHolder.java

示例7: getCalendarWeek

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static CalendarWeekVO getCalendarWeek(Date date) {
	GregorianCalendar cal = new GregorianCalendar();
	cal.setTime(date);
	int year = cal.get(GregorianCalendar.YEAR);
	int period;
	switch ((new GregorianCalendar(year, 0, 1)).get(GregorianCalendar.DAY_OF_WEEK)) {
		case GregorianCalendar.SUNDAY:
			period = -1;
			break;
		case GregorianCalendar.MONDAY:
			period = 0;
			break;
		case GregorianCalendar.TUESDAY:
			period = 1;
			break;
		case GregorianCalendar.WEDNESDAY:
			period = 2;
			break;
		case GregorianCalendar.THURSDAY:
			period = 3;
			break;
		case GregorianCalendar.FRIDAY:
			period = -3;
			break;
		case GregorianCalendar.SATURDAY:
			period = -2;
			break;
		default:
			period = 0;
	}
	int week = (int) ((cal.get(GregorianCalendar.DAY_OF_YEAR) - 1 + period) / 7d + 1);
	if (week > getWeeksOfYear(year)) {
		return new CalendarWeekVO(cal.getTime(), 1, year + 1);
	} else if (week == 0) {
		return new CalendarWeekVO(cal.getTime(), getWeeksOfYear(year - 1), year - 1);
	} else {
		return new CalendarWeekVO(cal.getTime(), week, year);
	}
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:40,代码来源:DateCalc.java

示例8: checkDate

import java.util.GregorianCalendar; //导入方法依赖的package包/类
private boolean checkDate(int month, int day) {
    final GregorianCalendar gc = new GregorianCalendar();
    gc.set(GregorianCalendar.YEAR, year);
    gc.set(GregorianCalendar.MONTH, month);
    gc.set(GregorianCalendar.DAY_OF_MONTH, day);
    return month == gc.get(GregorianCalendar.MONTH);
}
 
开发者ID:bcgov,项目名称:sbc-qsystem,代码行数:8,代码来源:TableCell.java

示例9: getTime

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/** Returns the current date and time as formatted string. */
private static String getTime() {
	GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance();
	String time = getTwoDigits(cal.get(Calendar.DAY_OF_MONTH)) + "." + getTwoDigits((cal.get(Calendar.MONTH) + 1)) + "."
			+ cal.get(Calendar.YEAR) + " " + getTwoDigits(cal.get(Calendar.HOUR_OF_DAY)) + ":"
			+ getTwoDigits(cal.get(Calendar.MINUTE)) + ":" + getTwoDigits(cal.get(Calendar.SECOND));
	return time;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:9,代码来源:ResultService.java

示例10: onStartCommand

import java.util.GregorianCalendar; //导入方法依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Utils.getController().setContext(getApplicationContext());
    reschedule();

    Date d = new Date();
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(d);

    if(calendar.get(Calendar.DAY_OF_WEEK) != Calendar.FRIDAY && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY)
        new NotificationHandler.KlausurplanNotification().send();

    Utils.logDebug("NotificationService (re)started!");
    return START_NOT_STICKY;
}
 
开发者ID:LCA311,项目名称:leoapp-sources,代码行数:16,代码来源:NotificationServiceWrapper.java

示例11: Test4197699

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * Week of year is wrong at the start and end of the year.
 */
public void Test4197699() {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setFirstDayOfWeek(MONDAY);
    cal.setMinimalDaysInFirstWeek(4);
    DateFormat fmt = new SimpleDateFormat("E dd MMM yyyy  'DOY='D 'WOY='w");
    fmt.setCalendar(cal);

    int[] DATA = {
        2000, JANUARY, 1, 52,
        2001, DECEMBER, 31, 1};

    for (int i = 0; i < DATA.length;) {
        cal.set(DATA[i++], DATA[i++], DATA[i++]);
        int expWOY = DATA[i++];
        int actWOY = cal.get(WEEK_OF_YEAR);
        if (expWOY == actWOY) {
            logln("Ok: " + fmt.format(cal.getTime()));
        } else {
            errln("FAIL: " + fmt.format(cal.getTime())
                    + ", expected WOY=" + expWOY);
            cal.add(DATE, -8);
            for (int j = 0; j < 14; ++j) {
                cal.add(DATE, 1);
                logln(fmt.format(cal.getTime()));
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:CalendarRegression.java

示例12: writeTIME

import java.util.GregorianCalendar; //导入方法依赖的package包/类
private void writeTIME() throws IOException
{
	if (param.isModificationTimeSet())
	{
		ChunkStream cs = new ChunkStream("tIME");

		Date date = param.getModificationTime();
		TimeZone gmt = TimeZone.getTimeZone("GMT");

		GregorianCalendar cal = new GregorianCalendar(gmt);
		cal.setTime(date);

		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH);
		int day = cal.get(Calendar.DAY_OF_MONTH);
		int hour = cal.get(Calendar.HOUR_OF_DAY);
		int minute = cal.get(Calendar.MINUTE);
		int second = cal.get(Calendar.SECOND);

		cs.writeShort(year);
		cs.writeByte(month + 1);
		cs.writeByte(day);
		cs.writeByte(hour);
		cs.writeByte(minute);
		cs.writeByte(second);

		cs.writeToStream(dataOutput);
		cs.close();
	}
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:31,代码来源:mxPngImageEncoder.java

示例13: isLeapYear

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static boolean isLeapYear(String ddate) {
    GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
    gc.setTime(strToDate(ddate));
    int year = gc.get(1);
    if (year % 400 == 0) {
        return true;
    }
    if (year % 4 != 0) {
        return false;
    }
    if (year % 100 == 0) {
        return false;
    }
    return true;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:16,代码来源:LetvDateUtils.java

示例14: setTime

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void setTime(long value) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(new Date(value));
    if (cal.get(1) < 1980) {
        this.modDate = 33;
        this.time = 0;
        return;
    }
    this.modDate = cal.get(5);
    this.modDate = ((cal.get(2) + 1) << 5) | this.modDate;
    this.modDate = ((cal.get(1) - 1980) << 9) | this.modDate;
    this.time = cal.get(13) >> 1;
    this.time = (cal.get(12) << 5) | this.time;
    this.time = (cal.get(11) << 11) | this.time;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:16,代码来源:TinkerZipEntry.java

示例15: TestGregorianChangeover

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * Test the behavior of the GregorianCalendar around the changeover.
 */
public void TestGregorianChangeover() {
    TimeZone savedZone = TimeZone.getDefault();
    /*
      Changeover -7 days: 1582/9/28 dow=6
      Changeover -6 days: 1582/9/29 dow=7
      Changeover -5 days: 1582/9/30 dow=1
      Changeover -4 days: 1582/10/1 dow=2
      Changeover -3 days: 1582/10/2 dow=3
      Changeover -2 days: 1582/10/3 dow=4
      Changeover -1 days: 1582/10/4 dow=5
      Changeover +0 days: 1582/10/15 dow=6
      Changeover +1 days: 1582/10/16 dow=7
      Changeover +2 days: 1582/10/17 dow=1
      Changeover +3 days: 1582/10/18 dow=2
      Changeover +4 days: 1582/10/19 dow=3
      Changeover +5 days: 1582/10/20 dow=4
      Changeover +6 days: 1582/10/21 dow=5
      Changeover +7 days: 1582/10/22 dow=6
      */
    int[] MON = {  9,  9,  9,10,10,10,10, 10, 10, 10, 10, 10, 10, 10, 10 };
    int[] DOM = { 28, 29, 30, 1, 2, 3, 4, 15, 16, 17, 18, 19, 20, 21, 22 };
    int[] DOW = {  6,  7,  1, 2, 3, 4, 5,  6,  7,  1,  2,  3,  4,  5,  6 };
    //                                     ^ <-Changeover Fri Oct 15 1582
    try {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
        @SuppressWarnings("deprecation")
        Date co = new Date(1582 - 1900, OCTOBER, 15);
        GregorianCalendar cal = new GregorianCalendar();
        int j = 0;
        for (int i = -7; i <= 7; ++i, ++j) {
            Date d = new Date(co.getTime() + i * ONE_DAY);
            cal.setTime(d);
            int y = cal.get(YEAR);
            int mon = cal.get(MONTH) + 1 - JANUARY;
            int dom = cal.get(DATE);
            int dow = cal.get(DAY_OF_WEEK);

            logln("Changeover " + (i >= 0 ? "+" : "") + i
                    + " days: " + y + "/" + mon + "/" + dom + " dow=" + dow);
            if (y != 1582 || mon != MON[j] || dom != DOM[j] || dow != DOW[j]) {
                errln(" Fail: Above line is wrong");
            }
        }
    } finally {
        TimeZone.setDefault(savedZone);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:51,代码来源:CalendarTest.java


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