Java:为什么不建议使用Date构造函数,而是使用什么? [英] Java: Why is the Date constructor deprecated, and what do I use instead?

查看:968
本文介绍了Java:为什么不建议使用Date构造函数,而是使用什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自C#世界,所以也没有经验的Java。只是被Eclipse告诉过, Date 已被弃用。

  Person p = new Person(); 
p.setDateOfBirth(new Date(1985,1,1));

为什么?应该使用什么(特别是在上面的情况下)?

解决方案

具体的Date构造函数已被弃用,改为使用
用于 Date 的JavaDoc描述哪些构造函数已被弃用,以及如何使用日历替换它们。


I come from the C# world, so not too experienced with Java yet. Was just told by Eclipse that the Date was deprecated.

Person p = new Person();
p.setDateOfBirth(new Date(1985, 1, 1));

Why? And what (especially in cases like above) should be used instead?

解决方案

The specific Date constructor is deprecated, and a Calendar should be used instead. The JavaDoc for Date describes which constructors are deprecated and how to replace them using a Calendar.

这篇关于Java:为什么不建议使用Date构造函数,而是使用什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆