java中 The method getHours() from the type Date is deprecated 代码怎么改?
j5=newJLabel("现在是"+ca1.get(Calendar.YEAR)+"年"+ca1.get(Calendar.MONTH)+"月"+ca1.get(Cal...
j5 = new JLabel("现在是" + ca1.get(Calendar.YEAR) + "年"
+ ca1.get(Calendar.MONTH) + "月" + ca1.get(Calendar.DATE) + "日"
+ String.valueOf(now.getHours()) + ":"
+ String.valueOf(now.getMinutes()) + ":"
+ String.valueOf(now.getSeconds()));
(now.getHour 、now.getMinutes 、 now.getSeconds)-------过时了
这些已过时的应该怎么改呀? 展开
+ ca1.get(Calendar.MONTH) + "月" + ca1.get(Calendar.DATE) + "日"
+ String.valueOf(now.getHours()) + ":"
+ String.valueOf(now.getMinutes()) + ":"
+ String.valueOf(now.getSeconds()));
(now.getHour 、now.getMinutes 、 now.getSeconds)-------过时了
这些已过时的应该怎么改呀? 展开
展开全部
过时的方法,不影响,可以继续使用,可能会在未来版本删除。
如果看着不爽,可以在其方法上面加上
@SuppressWarnings("deprecation")
如:
public class $ {
@SuppressWarnings("deprecation")
public static void main(String[] args) {
Date now = new Date();
System.out.println(now.getSeconds());
}
}
追答
package org.test.java;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Jichu2 {
public static void main(String[] args) {
Calendar c = Calendar.getInstance();
Format f = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
System.out.println("方法一:" + f.format(c.getTime()));
String str = c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH) + 1) + "月" + c.get(Calendar.DAY_OF_MONTH) + "日 "
+ c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND);
System.out.println("方法二:" + str);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询