Java 在方法上显示走向线
Java Show Strike Line on Methods
为什么在 getDate()
、getMonth()
和 getYear()
上显示罢工线。这些方法用于获取当前日期、月份和年份,但我不知道为什么这些方法显示罢工。
代码:
public class hello {
public static void main(String[] args) {
int days;
int month;
int year;
days = 24;
month = 10;
year = 1994;
System.out.println("Date of Birth: " + days + "/" + month + "/" + year);
Date d = new Date();
int t = d.getDate();
int x = d.getMonth() + 1;
int f = d.getYear() + 1900;
System.out.println("Current Date: " + t + "/" + x + "/" + f);
}
}
像 Eclipse 这样的 IDE 会在这些方法被弃用时删除它们,这意味着不推荐使用它们,因为有更好的选择。见 Javadocs of getDate()
:
Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.DAY_OF_MONTH)
.
使用Calendar
方法:
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_MONTH);
int month = calendar.get(Calendar.MONTH) + 1;
int year = calendar.get(Calendar.YEAR);
那是因为它们已被弃用。如果您在函数上方的信息中设置 @deprecated,它会删除大多数 IDE 中的方法。
这些特定函数已被弃用,因为较新的 Calendar
是更好的选择。
试试这个。
int days;
int month;
int year;
days=24;
month=10;
year=1994;
System.out.println("Date of Birth: "+days+ "/" +month+ "/" +year);
LocalDate dd = LocalDate.of(year, month, days);
System.out.println("Current Date: " + dd);
System.out.println("Month: " + dd.getMonth());
System.out.println("Day: " + dd.getDayOfMonth());
System.out.println("Year: " + dd.getYear());
//If you would add year
LocalDate newYear = dd.plusYears(10);
System.out.println("New Date: " + newYear);
这是输出:
Date of Birth: 24/10/1994
Current Date: 1994-10-24
Month: OCTOBER
Day: 24
Year: 1994
New Date: 2004-10-24
为什么在 getDate()
、getMonth()
和 getYear()
上显示罢工线。这些方法用于获取当前日期、月份和年份,但我不知道为什么这些方法显示罢工。
代码:
public class hello {
public static void main(String[] args) {
int days;
int month;
int year;
days = 24;
month = 10;
year = 1994;
System.out.println("Date of Birth: " + days + "/" + month + "/" + year);
Date d = new Date();
int t = d.getDate();
int x = d.getMonth() + 1;
int f = d.getYear() + 1900;
System.out.println("Current Date: " + t + "/" + x + "/" + f);
}
}
像 Eclipse 这样的 IDE 会在这些方法被弃用时删除它们,这意味着不推荐使用它们,因为有更好的选择。见 Javadocs of getDate()
:
Deprecated. As of JDK version 1.1, replaced by
Calendar.get(Calendar.DAY_OF_MONTH)
.
使用Calendar
方法:
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_MONTH);
int month = calendar.get(Calendar.MONTH) + 1;
int year = calendar.get(Calendar.YEAR);
那是因为它们已被弃用。如果您在函数上方的信息中设置 @deprecated,它会删除大多数 IDE 中的方法。
这些特定函数已被弃用,因为较新的 Calendar
是更好的选择。
试试这个。
int days;
int month;
int year;
days=24;
month=10;
year=1994;
System.out.println("Date of Birth: "+days+ "/" +month+ "/" +year);
LocalDate dd = LocalDate.of(year, month, days);
System.out.println("Current Date: " + dd);
System.out.println("Month: " + dd.getMonth());
System.out.println("Day: " + dd.getDayOfMonth());
System.out.println("Year: " + dd.getYear());
//If you would add year
LocalDate newYear = dd.plusYears(10);
System.out.println("New Date: " + newYear);
这是输出:
Date of Birth: 24/10/1994
Current Date: 1994-10-24
Month: OCTOBER
Day: 24
Year: 1994
New Date: 2004-10-24