本文整理汇总了Java中java.util.Date.getYear方法的典型用法代码示例。如果您正苦于以下问题:Java Date.getYear方法的具体用法?Java Date.getYear怎么用?Java Date.getYear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Date
的用法示例。
在下文中一共展示了Date.getYear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setTime
import java.util.Date; //导入方法依赖的package包/类
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);
}
示例2: getAge
import java.util.Date; //导入方法依赖的package包/类
/**根据生日获取年龄
* @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()});
}
示例3: getSmartBirthday
import java.util.Date; //导入方法依赖的package包/类
/**
* @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()) + "岁";
}
示例4: javaToDosTime
import java.util.Date; //导入方法依赖的package包/类
/**
* 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;
}
示例5: getTime
import java.util.Date; //导入方法依赖的package包/类
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);
}
示例6: isToday
import java.util.Date; //导入方法依赖的package包/类
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;
}
示例7: feature
import java.util.Date; //导入方法依赖的package包/类
@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;
}
示例8: weekNumber
import java.util.Date; //导入方法依赖的package包/类
@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;
}
示例9: getTimeState
import java.util.Date; //导入方法依赖的package包/类
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;
}
示例10: javaToDosTime
import java.util.Date; //导入方法依赖的package包/类
/**
* 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: calcAge
import java.util.Date; //导入方法依赖的package包/类
private int calcAge(Date birthday) {
return new Date().getYear() - birthday.getYear();
}
示例12: toRPCDate
import java.util.Date; //导入方法依赖的package包/类
public static CalDate toRPCDate(Date date) {
return new CalDate(date.getYear() + 1900, date.getMonth() + 1, date.getDate());
}
示例13: inOneDay
import java.util.Date; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
protected boolean inOneDay(Date date1, Date date2) {
return (date1.getYear() == date2.getYear()) && (date1.getMonth() == date2.getMonth())
&& (date1.getDate() == date2.getDate());
}
示例14: isInfFuture
import java.util.Date; //导入方法依赖的package包/类
public static boolean isInfFuture(Date date) {
return date.getYear() > 8000; // Hacky, but needs to match Ruby's Time::INF_FUTURE
}
示例15: isInfPast
import java.util.Date; //导入方法依赖的package包/类
public static boolean isInfPast(Date date) {
return date.getYear() < -10000;
}