一个取日期的问题

jianxuan 2004-11-22 10:35:40
我用这个方法取当前日期
java.util.Date newDate = new java.util.Date(newVisDate);
java.text.DateFormat dfTemp = java.text.DateFormat.getDateTimeInstance();
infoVisDate=dfTemp.format(newDate);

编译时告诉我:
Note: E:\java_test\infoDes.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.

Process completed.

java不推荐?那别的什么方法能取到当前时间呢?
...全文
122 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyuestar 2004-11-22
  • 打赏
  • 举报
回复
public static String getSysDateTime() {
String dateTime = "";
Date sysDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
StringBuffer tb = new StringBuffer();
dateTime = sdf.format(sysDate , tb, new FieldPosition(0)).toString();
return dateTime;
}
catblue 2004-11-22
  • 打赏
  • 举报
回复
SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd");
String time=formatter.format(new Date());//得到当前时间
jackkui 2004-11-22
  • 打赏
  • 举报
回复
Calendar calendar = Calendar.getInstance();
然后使用Calendar中的方法就可以了。
funcreal 2004-11-22
  • 打赏
  • 举报
回复
GregorianCalendar calendar = new GregorianCalendar();
String sdt = calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DATE);
这个是得到类似于yyyy-mm-dd的时间格式,相信你能看出如何写出你要的格式了。
jianxuan 2004-11-22
  • 打赏
  • 举报
回复
帮帮我。
zez 2004-11-22
  • 打赏
  • 举报
回复
Date date = new Date() 就完了,你怎么那么麻烦???
PoemCode 2004-11-22
  • 打赏
  • 举报
回复
public abstract class Calendar
extends Object
implements Serializable, Cloneable, Comparable<Calendar>

The Calendar class is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating the calendar fields, such as getting the date of the next week. An instant in time can be represented by a millisecond value that is an offset from the Epoch, January 1, 1970 00:00:00.000 GMT (Gregorian).

PoemCode 2004-11-22
  • 打赏
  • 举报
回复
你需要看一看api doc里的Calendar类,
jackkui(键盘上的武士)的回复是最为简捷的方法,
楼主使用的方法在1.4版本之后已经不支持了。

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧