本文整理匯總了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;
}