getYear ( )源码实例Demo

java.util.Date#getYear ( )源码实例Demo

下面列出了java.util.Date#getYear ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Albianj2   文件: AlbianRemoteUNIDService.java
public void unpack(BigInteger bi, RefArg<Timestamp> time,
                   RefArg<Integer> sed, RefArg<Integer> idx) {
    long r32 = bi.divide(new BigInteger("1000000000")).longValue();
    int next = bi.divide(new BigInteger("100")).intValue();
    int i = bi.modInverse(new BigInteger("100")).intValue();
    if (null != time) {
        Date dt = AlbianDateTime.dateAddSeconds(2015, 1, 1, r32);
        @SuppressWarnings("deprecation")
        Timestamp tt = new Timestamp(dt.getYear(), dt.getMonth(),
                dt.getDate(), dt.getHours(), dt.getMinutes(),
                dt.getSeconds(), 0);
        time.setValue(tt);
    }
    if (null != sed)
        sed.setValue(next);
    if (null != idx)
        idx.setValue(i);
}
 
源代码2 项目: MaterialWeCenter   文件: ArticleAdapter.java
private String getTime(long dateLong) {


        final long SECOND_TO_LONG = 1000l;
        final long MINUTE_TO_LONG = SECOND_TO_LONG * 60;
        final long HOUR_TO_LONG = MINUTE_TO_LONG * 60;
        final long DAY_TO_LONG = HOUR_TO_LONG * 24;

        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");

        long ct = System.currentTimeMillis();
        long cost = ct - dateLong * 1000l;

        Date ctDate = new Date(ct);
        Date longDate = new Date(dateLong * 1000l);

        if (cost < MINUTE_TO_LONG) {
            return cost / SECOND_TO_LONG + "秒前";
        } else if (cost < HOUR_TO_LONG) {
            return cost / MINUTE_TO_LONG + "分钟前";
        } else if (cost < DAY_TO_LONG) {
            return cost / HOUR_TO_LONG + "小时前";
        } else if (ctDate.getYear() > longDate.getYear()) {
            return sdf2.format(longDate);
        } else return sdf.format(longDate);

    }
 
源代码3 项目: jdk8u-jdk   文件: ZipUtils.java
public static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
源代码4 项目: hottub   文件: ZipUtils.java
public static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
源代码5 项目: shortyz   文件: ChronDownloader.java
@Override
protected String getFileName(Date date) {
    String name = "cs" + (date.getYear() - 100) +
        nf.format(date.getMonth() + 1) + nf.format(date.getDate()) +
        ".puz";
    return name;
}
 
源代码6 项目: shortyz   文件: InkwellDownloader.java
@Override
protected String getFileName(Date date) {
    if (date.getDay() != 5) {
        return null;
    }
    String name = "vv" + (date.getYear() - 100) +
        nf.format(date.getMonth() + 1) + nf.format(date.getDate()) +
        ".puz";

    return name;
}
 
源代码7 项目: iaf   文件: FileUtils.java
public static File getRollingFile(String directory, String filenamePrefix, String dateformat, String filenameSuffix, int retentionDays) {
	
	final long millisPerDay=24*60*60*1000;

	if (directory==null) {
		return null;
	}
	Date now=new Date();

	String filename=filenamePrefix+DateUtils.format(now,dateformat)+filenameSuffix;
	File result = new File(directory+"/"+filename);
	if (!result.exists()) {
		int year=now.getYear();
		int month=now.getMonth();
		int date=now.getDate();
	
		long thisMorning = new Date(year, month, date).getTime();

		long deleteBefore = thisMorning - retentionDays * millisPerDay;

		WildCardFilter filter = new WildCardFilter(filenamePrefix+"*"+filenameSuffix);
		File dir = new File(directory);
		File[] files = dir.listFiles(filter);

		int count = (files == null ? 0 : files.length);
		for (int i = 0; i < count; i++) {
			File file = files[i];
			if (file.isDirectory()) {
				continue;
			}
			if (file.lastModified()<deleteBefore) {
				file.delete();
			}
		}
	}
	
	return result;

}
 
源代码8 项目: openjdk-jdk8u   文件: ZipUtils.java
public static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
源代码9 项目: shortyz   文件: NYTDownloader.java
@Override
    protected String createUrlSuffix(Date date) {
//		if(date.getTime() < lastDailyPathTime) {
        return "daily-" + (date.getYear() + 1900) + "-"
                + this.nf.format(date.getMonth() + 1) + "-"
                + this.nf.format(date.getDate()) + ".puz";
//		} else {
//			return
//		}
    }
 
源代码10 项目: hottub   文件: ZipUtils.java
/**
 * Converts Java time to DOS time.
 */
@SuppressWarnings("deprecation") // Use of date methods
private static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return ZipEntry.DOSTIME_BEFORE_1980;
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
源代码11 项目: openjdk-8   文件: Bug6772689.java
public static void main(String[] args) {
    TimeZone defaultTimeZone = TimeZone.getDefault();
    int errors = 0;

    Calendar cal = new GregorianCalendar(BEGIN_YEAR, MARCH, 1);
    String[] tzids = TimeZone.getAvailableIDs();
    try {
        for (String id : tzids) {
            TimeZone tz = TimeZone.getTimeZone(id);
            if (!tz.useDaylightTime()) {
                continue;
            }
            TimeZone.setDefault(tz);

          dateloop:
            // Use future dates because sun.util.calendar.ZoneInfo
            // delegates offset transition calculations to a SimpleTimeZone
            // (after 2038 as of JDK7).
            for (int year = BEGIN_YEAR; year < END_YEAR; year++) {
                for (int month = MARCH; month <= NOVEMBER; month++) {
                    cal.set(year, month, 1, 15, 0, 0);
                    int maxDom = cal.getActualMaximum(DAY_OF_MONTH);
                    for (int dom = 1; dom <= maxDom; dom++) {
                        Date date = new Date(year - 1900, month, dom);
                        if (date.getYear()+1900 != year
                            || date.getMonth() != month
                            || date.getDate() != dom) {
                            System.err.printf("%s: got %04d-%02d-%02d, expected %04d-%02d-%02d%n",
                                              id,
                                              date.getYear() + 1900,
                                              date.getMonth() + 1,
                                              date.getDate(),
                                              year,
                                              month + 1,
                                              dom);
                            errors++;
                            break dateloop;
                        }
                    }
                }
            }
        }
    } finally {
        // Restore the default TimeZone.
        TimeZone.setDefault(defaultTimeZone);
    }
    if (errors > 0) {
        throw new RuntimeException("Transition test failed");
    }
}
 
源代码12 项目: AndroidAPS   文件: WearUtil.java
public static String dateTimeText(long timeInMs) {
    Date d = new Date(timeInMs);
    return "" + d.getDay() + "." + d.getMonth() + "." + d.getYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
}
 
源代码13 项目: hottub   文件: Bug6772689.java
public static void main(String[] args) {
    TimeZone defaultTimeZone = TimeZone.getDefault();
    int errors = 0;

    Calendar cal = new GregorianCalendar(BEGIN_YEAR, MARCH, 1);
    String[] tzids = TimeZone.getAvailableIDs();
    try {
        for (String id : tzids) {
            TimeZone tz = TimeZone.getTimeZone(id);
            if (!tz.useDaylightTime()) {
                continue;
            }
            TimeZone.setDefault(tz);

          dateloop:
            // Use future dates because sun.util.calendar.ZoneInfo
            // delegates offset transition calculations to a SimpleTimeZone
            // (after 2038 as of JDK7).
            for (int year = BEGIN_YEAR; year < END_YEAR; year++) {
                for (int month = MARCH; month <= NOVEMBER; month++) {
                    cal.set(year, month, 1, 15, 0, 0);
                    int maxDom = cal.getActualMaximum(DAY_OF_MONTH);
                    for (int dom = 1; dom <= maxDom; dom++) {
                        Date date = new Date(year - 1900, month, dom);
                        if (date.getYear()+1900 != year
                            || date.getMonth() != month
                            || date.getDate() != dom) {
                            System.err.printf("%s: got %04d-%02d-%02d, expected %04d-%02d-%02d%n",
                                              id,
                                              date.getYear() + 1900,
                                              date.getMonth() + 1,
                                              date.getDate(),
                                              year,
                                              month + 1,
                                              dom);
                            errors++;
                            break dateloop;
                        }
                    }
                }
            }
        }
    } finally {
        // Restore the default TimeZone.
        TimeZone.setDefault(defaultTimeZone);
    }
    if (errors > 0) {
        throw new RuntimeException("Transition test failed");
    }
}
 
源代码14 项目: TencentKona-8   文件: Bug6772689.java
public static void main(String[] args) {
    TimeZone defaultTimeZone = TimeZone.getDefault();
    int errors = 0;

    Calendar cal = new GregorianCalendar(BEGIN_YEAR, MARCH, 1);
    String[] tzids = TimeZone.getAvailableIDs();
    try {
        for (String id : tzids) {
            TimeZone tz = TimeZone.getTimeZone(id);
            if (!tz.useDaylightTime()) {
                continue;
            }
            TimeZone.setDefault(tz);

          dateloop:
            // Use future dates because sun.util.calendar.ZoneInfo
            // delegates offset transition calculations to a SimpleTimeZone
            // (after 2038 as of JDK7).
            for (int year = BEGIN_YEAR; year < END_YEAR; year++) {
                for (int month = MARCH; month <= NOVEMBER; month++) {
                    cal.set(year, month, 1, 15, 0, 0);
                    int maxDom = cal.getActualMaximum(DAY_OF_MONTH);
                    for (int dom = 1; dom <= maxDom; dom++) {
                        Date date = new Date(year - 1900, month, dom);
                        if (date.getYear()+1900 != year
                            || date.getMonth() != month
                            || date.getDate() != dom) {
                            System.err.printf("%s: got %04d-%02d-%02d, expected %04d-%02d-%02d%n",
                                              id,
                                              date.getYear() + 1900,
                                              date.getMonth() + 1,
                                              date.getDate(),
                                              year,
                                              month + 1,
                                              dom);
                            errors++;
                            break dateloop;
                        }
                    }
                }
            }
        }
    } finally {
        // Restore the default TimeZone.
        TimeZone.setDefault(defaultTimeZone);
    }
    if (errors > 0) {
        throw new RuntimeException("Transition test failed");
    }
}
 
源代码15 项目: refactoring-kata   文件: ResidentialSite.java
private int DayOfYear(Date arg) {
    int result;
    switch (arg.getMonth()) {
        case 0:
            result = 0;
            break;
        case 1:
            result = 31;
            break;
        case 2:
            result = 59;
            break;
        case 3:
            result = 90;
            break;
        case 4:
            result = 120;
            break;
        case 5:
            result = 151;
            break;
        case 6:
            result = 181;
            break;
        case 7:
            result = 212;
            break;
        case 8:
            result = 243;
            break;
        case 9:
            result = 273;
            break;
        case 10:
            result = 304;
            break;
        case 11:
            result = 334;
            break;
        default:
            throw new IllegalArgumentException();
    }
    result += arg.getDate();

    //check leap year
    if ((arg.getYear() % 4 == 0) && ((arg.getYear() % 100 != 0) ||
            ((arg.getYear() + 1900) % 400 == 0))) {
        result++;
    }

    return result;
}
 
源代码16 项目: EasyVPN-Free   文件: X509Utils.java
public static int getMonthsDifference(Date date1, Date date2) {
    int m1 = date1.getYear() * 12 + date1.getMonth();
    int m2 = date2.getYear() * 12 + date2.getMonth();
    return m2 - m1 + 1;
}
 
源代码17 项目: AutoTest   文件: TimeUtils.java
private static boolean isToday(Date date) {
    Date now = new Date();
    return (date.getYear() == now.getYear()) && (date.getMonth() == now.getMonth()) && (date.getDate() == now.getDate());
}
 
源代码18 项目: shortyz   文件: JonesinDownloader.java
@Override
protected String createUrlSuffix(Date date) {
    return "jz" + (date.getYear() - 100) + nf.format(date.getMonth() + 1) + nf.format(date.getDate()) + ".puz";
}
 
源代码19 项目: swellrt   文件: DateUtils.java
/**
* @return true if a date occurs on the same day as today.
*/
private boolean onSameDay(Date date, Date now) {
  return (date.getDate() == now.getDate())
      && (date.getMonth() == now.getMonth())
      && (date.getYear() == now.getYear());
}
 
源代码20 项目: coming   文件: Time_12_LocalDate_s.java
/**
 * Constructs a LocalDate from a <code>java.util.Date</code>
 * using exactly the same field values.
 * <p>
 * Each field is queried from the Date and assigned to the LocalDate.
 * This is useful if you have been using the Date as a local date,
 * ignoring the zone.
 * <p>
 * One advantage of this method is that this method is unaffected if the
 * version of the time zone data differs between the JDK and Joda-Time.
 * That is because the local field values are transferred, calculated using
 * the JDK time zone data and without using the Joda-Time time zone data.
 * <p>
 * This factory method always creates a LocalDate with ISO chronology.
 *
 * @param date  the Date to extract fields from, not null
 * @return the created local date, not null
 * @throws IllegalArgumentException if the calendar is null
 * @throws IllegalArgumentException if the date is invalid for the ISO chronology
 */
@SuppressWarnings("deprecation")
public static LocalDate fromDateFields(Date date) {
    if (date == null) {
        throw new IllegalArgumentException("The date must not be null");
    }
        // handle years in era BC
    return new LocalDate(
        date.getYear() + 1900,
        date.getMonth() + 1,
        date.getDate()
    );
}