Java Code Examples for java.util.Date#getYear()
The following examples show how to use
java.util.Date#getYear() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlbianRemoteUNIDService.java From Albianj2 with BSD 3-Clause "New" or "Revised" License | 6 votes |
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); }
Example 2
Source File: ZipUtils.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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; }
Example 3
Source File: ZipUtils.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 4
Source File: NYTDownloader.java From shortyz with GNU General Public License v3.0 | 5 votes |
@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 // } }
Example 5
Source File: ZipUtils.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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; }
Example 6
Source File: FileUtils.java From iaf with Apache License 2.0 | 5 votes |
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; }
Example 7
Source File: InkwellDownloader.java From shortyz with GNU General Public License v3.0 | 5 votes |
@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; }
Example 8
Source File: ChronDownloader.java From shortyz with GNU General Public License v3.0 | 5 votes |
@Override protected String getFileName(Date date) { String name = "cs" + (date.getYear() - 100) + nf.format(date.getMonth() + 1) + nf.format(date.getDate()) + ".puz"; return name; }
Example 9
Source File: ZipUtils.java From hottub with GNU General Public License v2.0 | 5 votes |
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; }
Example 10
Source File: ArticleAdapter.java From MaterialWeCenter with Apache License 2.0 | 5 votes |
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); }
Example 11
Source File: Bug6772689.java From hottub with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 12
Source File: Bug6772689.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 13
Source File: WearUtil.java From AndroidAPS with GNU Affero General Public License v3.0 | 4 votes |
public static String dateTimeText(long timeInMs) { Date d = new Date(timeInMs); return "" + d.getDay() + "." + d.getMonth() + "." + d.getYear() + " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds(); }
Example 14
Source File: ResidentialSite.java From refactoring-kata with MIT License | 4 votes |
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; }
Example 15
Source File: X509Utils.java From EasyVPN-Free with GNU General Public License v3.0 | 4 votes |
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; }
Example 16
Source File: Bug6772689.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 17
Source File: TimeUtils.java From AutoTest with MIT License | 4 votes |
private static boolean isToday(Date date) { Date now = new Date(); return (date.getYear() == now.getYear()) && (date.getMonth() == now.getMonth()) && (date.getDate() == now.getDate()); }
Example 18
Source File: JonesinDownloader.java From shortyz with GNU General Public License v3.0 | 4 votes |
@Override protected String createUrlSuffix(Date date) { return "jz" + (date.getYear() - 100) + nf.format(date.getMonth() + 1) + nf.format(date.getDate()) + ".puz"; }
Example 19
Source File: DateUtils.java From swellrt with Apache License 2.0 | 4 votes |
/** * @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()); }
Example 20
Source File: Time_12_LocalDate_s.java From coming with MIT License | 3 votes |
/** * 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() ); }