您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页java Calendar 的一个坑

java Calendar 的一个坑

来源:伴沃教育

刚开始使用new Date(),并通过date.getMonth(),和date.getDay()获取,发现获取时间一直不对,后来发现这两个获取方式是jdk1.1版本的,现在已经不用了.
后来查看[Java ]doc文档,MONTH字段解释如下

Field number for get and set indicating the month. 
This is a calendar-specific value. 
The first month of the year is JANUARY which is 0; 
the last depends on the number of months in a year.

马个鸡,这家伙不就是和数组list一个样吗,下标从0开始算得...

int month = (date.get(Calendar.MONTH))+1;        
int day = date.get(Calendar.DAY_OF_MONTH);

获取当前的月份和日期
试了一下,果然正确

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务