我在Cassandra列系列中有一个日期列.当我使用datastax
java API从这个CF中检索数据时,这个日期对象可以作为一个java.util.Date对象.
它有一个getYear()方法,但它已被弃用.相应的javadoc说:
As of JDK version 1.1,replaced by Calendar.get(Calendar.YEAR) – 1900.
如何正确从这个日期对象获取年,月,日属性?
解决方法
你可以尝试像tihs吗?
// create a calendar Calendar cal = Calendar.getInstance(); cal.setTime(datetime); //use java.util.Date object as arguement // get the value of all the calendar date fields. System.out.println("Calendar's Year: " + cal.get(Calendar.YEAR)); System.out.println("Calendar's Month: " + cal.get(Calendar.MONTH)); System.out.println("Calendar's Day: " + cal.get(Calendar.DATE));
如javadocs年所述;
@Deprecated public int getYear() Deprecated. As of JDK version 1.1,replaced by Calendar.get(Calendar.YEAR) – 1900. Returns a value that is the result of subtracting 1900 from the year that contains or begins with the instant in time represented by this Date object,as interpreted in the local time zone. Returns: the year represented by this date,minus 1900.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。