Java Code Examples for java.util.Date.getYear()

The following are Jave code examples for showing how to use getYear() of the java.util.Date class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: javaide   File: ZioEntry.java   View Source Code Vote up 8 votes
public void setTime(long time) {
    Date d = new Date(time);
    long dtime;
    int year = d.getYear() + 1900;
    if (year < 1980) {
        dtime = (1 << 21) | (1 << 16);
    }
    else {
        dtime = (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
        d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
        d.getSeconds() >> 1;
    }

    modificationDate = (short)(dtime >> 16);
    modificationTime = (short)(dtime & 0xFFFF);
}
 
Example 2
Project: mobile-store   File: ZioEntry.java   View Source Code Vote up 6 votes
public void setTime(long time) {
    Date d = new Date(time);
    long dtime;
    int year = d.getYear() + 1900;
    if (year < 1980) {
        dtime = (1 << 21) | (1 << 16);
    }
    else {
        dtime = (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
        d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
        d.getSeconds() >> 1;
    }

    modificationDate = (short)(dtime >> 16);
    modificationTime = (short)(dtime & 0xFFFF);
}
 
Example 3
Project: GitHub   File: TimeUtil.java   View Source Code Vote up 5 votes
/**根据生日获取年龄
 * @param birthday
 * @return
 */
public static int getAge(Date birthday) {
	if (birthday == null) {
		return 0;
	}
	if (birthday.getYear() > getDateDetail(System.currentTimeMillis())[0]) {
		birthday.setYear(birthday.getYear() - TimeUtil.SYSTEM_START_DATE[0]);
	}

	return getAge(new int[]{birthday.getYear(), birthday.getMonth(), birthday.getDay()});
}
 
Example 4
Project: GitHub   File: TimeUtil.java   View Source Code Vote up 5 votes
/**
 * @param birthday
 * @return
 */
public static String getSmartBirthday(Date birthday) {
	if (birthday == null) {
		return "";
	}
	if (birthday.getYear() > getDateDetail(System.currentTimeMillis())[0]) {
		birthday.setYear(birthday.getYear() - TimeUtil.SYSTEM_START_DATE[0]);
	}

	return getSmartBirthday(birthday.getTime(), false) + " " + (TimeUtil
			.getDateDetail(System.currentTimeMillis())[0] - birthday.getYear()) + "岁";
}
 
Example 5
Project: GitHub   File: TimeUtil.java   View Source Code Vote up 5 votes
/**根据生日获取年龄
 * @param birthday
 * @return
 */
public static int getAge(Date birthday) {
	if (birthday == null) {
		return 0;
	}
	if (birthday.getYear() > getDateDetail(System.currentTimeMillis())[0]) {
		birthday.setYear(birthday.getYear() - TimeUtil.SYSTEM_START_DATE[0]);
	}

	return getAge(new int[]{birthday.getYear(), birthday.getMonth(), birthday.getDay()});
}
 
Example 6
Project: GitHub   File: TimeUtil.java   View Source Code Vote up 5 votes
/**
 * @param birthday
 * @return
 */
public static String getSmartBirthday(Date birthday) {
	if (birthday == null) {
		return "";
	}
	if (birthday.getYear() > getDateDetail(System.currentTimeMillis())[0]) {
		birthday.setYear(birthday.getYear() - TimeUtil.SYSTEM_START_DATE[0]);
	}

	return getSmartBirthday(birthday.getTime(), false) + " " + (TimeUtil
			.getDateDetail(System.currentTimeMillis())[0] - birthday.getYear()) + "岁";
}
 
Example 7
Project: OpenJSharp   File: ZipUtils.java   View Source Code Vote up 5 votes
/**
 * Converts Java time to DOS time.
 */
@SuppressWarnings("deprecation") // Use of date methods
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 8
Project: PangciACG   File: QuestionDetailAdapter.java   View Source Code Vote up 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 9
Project: My-Blog   File: DateKit.java   View Source Code Vote up 5 votes
public static boolean isToday(Date date) {
    Date now = new Date();
    boolean result = true;
    result &= date.getYear() == now.getYear();
    result &= date.getMonth() == now.getMonth();
    result &= date.getDate() == now.getDate();
    return result;
}
 
Example 10
Project: smile_1.5.0_java7   File: DateFeature.java   View Source Code Vote up 5 votes
@Override
@SuppressWarnings("deprecation")
public double[] feature(Date date) {
    double[] x = new double[types.length];
    for (int i = 0; i < types.length; i++)
    switch (types[i]) {
        case YEAR:
            x[i] = 1900 + date.getYear();
            break;
        case MONTH:
            x[i] = date.getMonth();
            break;
        case DAY_OF_MONTH:
            x[i] = date.getDate();
            break;
        case DAY_OF_WEEK:
            x[i] = date.getDay();
            break;
        case HOURS:
            x[i] = date.getHours();
            break;
        case MINUTES:
            x[i] = date.getMinutes();
            break;
        case SECONDS:
            x[i] = date.getSeconds();
            break;
        default:
            throw new IllegalStateException("Unknown date feature type: " + types[i]);
    }
    return x;
}
 
Example 11
Project: PangciACG   File: AnswerDetailAdapter.java   View Source Code Vote up 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 12
Project: unitimes   File: SingleDateSelector.java   View Source Code Vote up 5 votes
@SuppressWarnings("deprecation")
static int weekNumber(int year, int month) {
	Date d = new Date(year - 1900, month - 1, 1);
	while (d.getDay() != CalendarUtil.getStartingDayOfWeek()) d.setDate(d.getDate() - 1);
	int y = d.getYear();
	int week = 0;
	while (d.getYear() == y) { d.setDate(d.getDate() - 7); week += 1; }
	return week;
}
 
Example 13
Project: Programmers   File: Util.java   View Source Code Vote up 5 votes
public static boolean getTimeState(long time) {
    boolean output;

    Date last = new Date(time);
    Date current = new Date(System.currentTimeMillis());

    output = last.getYear() < current.getYear() ||
            last.getMonth() < current.getMonth() ||
            last.getDay() < current.getDay() ||
            last.getHours() < current.getHours() ||
            last.getMinutes() < current.getMinutes();

    return output;
}
 
Example 14
Project: jdk8u-jdk   File: ZipUtils.java   View Source Code Vote up 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 15
Project: boohee_v5.6   File: QNCalc.java   View Source Code Vote up 4 votes
private int calcAge(Date birthday) {
    return new Date().getYear() - birthday.getYear();
}
 
Example 16
Project: calendar-component   File: DateConstants.java   View Source Code Vote up 4 votes
public static CalDate toRPCDate(Date date) {
    return new CalDate(date.getYear() + 1900, date.getMonth() + 1, date.getDate());
}
 
Example 17
Project: acmeair   File: FlightService.java   View Source Code Vote up 4 votes
@SuppressWarnings("deprecation")
protected boolean inOneDay(Date date1, Date date2) {
    return (date1.getYear() == date2.getYear()) && (date1.getMonth() == date2.getMonth())
            && (date1.getDate() == date2.getDate());
}
 
Example 18
Project: ProjectAres   File: TimeUtils.java   View Source Code Vote up 4 votes
public static boolean isInfFuture(Date date) {
    return date.getYear() > 8000; // Hacky, but needs to match Ruby's Time::INF_FUTURE
}
 
Example 19
Project: ProjectAres   File: TimeUtils.java   View Source Code Vote up 4 votes
public static boolean isInfPast(Date date) {
    return date.getYear() < -10000;
}
 
Example 20
Project: openjdk-jdk10   File: CompilationStatistics.java   View Source Code Vote up 4 votes
@SuppressWarnings("deprecation")
public static void clear(String dumpName) {
    try {
        ConcurrentLinkedDeque<CompilationStatistics> snapshot = list;
        long snapshotZeroTime = zeroTime;

        list = new ConcurrentLinkedDeque<>();
        zeroTime = System.nanoTime();

        Date now = new Date();
        String dateString = (now.getYear() + 1900) + "-" + (now.getMonth() + 1) + "-" + now.getDate() + "-" + now.getHours() + "" + now.getMinutes();

        dumpCompilations(snapshot, dumpName, dateString);

        try (FileOutputStream fos = new FileOutputStream("timeline_" + dateString + "_" + dumpName + ".csv", true); PrintStream out = new PrintStream(fos)) {

            long[] timeSpent = new long[10000];
            int maxTick = 0;
            for (CompilationStatistics stats : snapshot) {
                long start = stats.startTime - snapshotZeroTime;
                long duration = stats.duration;
                if (start < 0) {
                    duration -= -start;
                    start = 0;
                }

                int tick = (int) (start / RESOLUTION);
                long timeLeft = RESOLUTION - (start % RESOLUTION);

                while (tick < timeSpent.length && duration > 0) {
                    if (tick > maxTick) {
                        maxTick = tick;
                    }
                    timeSpent[tick] += Math.min(timeLeft, duration);
                    duration -= timeLeft;
                    tick++;
                    timeLeft = RESOLUTION;
                }
            }
            String timelineName = System.getProperty("stats.timeline.name");
            if (timelineName != null && !timelineName.isEmpty()) {
                out.printf("%s%c", CSVUtil.Escape.escape(timelineName), CSVUtil.SEPARATOR);
            }
            for (int i = 0; i < maxTick; i++) {
                out.printf("%d%c", normalize(timeSpent[i]), CSVUtil.SEPARATOR);
            }
            // print last column
            out.printf("%d", normalize(timeSpent[maxTick]));
            out.println();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}