StupidBeauty
Read times:829Posted at:Mon Jul 29 19:48:51 2013
- no title specified

Java用户注意,Calendar类中,月份的数值是从0开始的

Java.util.Calendar类中,其MONTH属性,以数值0来表示一月 ,依此类推。 而不是以数值1来表示一月。 本座搜索到的一篇勃客里,直接以MONTH属性的值作为当前月份来显示,本座也是照着抄来代码用的,在测试过程中看到运行结果时,困扰了狠久。 经过研究,才发现数值是从0开始的。

例如,今天 是2013.7.30,以下代码:

package com.stupidbeauty.calendartest;

import java.util.Calendar;

public class CalendarTest

{

public static void main(String[] args)

{

Calendar c=Calendar. getInstance (); //获取日历实例。

System. out .println(c.get(Calendar. MONTH )+ "." +c.get(Calendar. DAY_OF_MONTH )); //输出两个分量。

} //public static void main(String[] args)

} //public class CalendarTest

其运行结果是:

6.30

可能 是因为Calendar类是最早出现在java中的一批类,因此带有C语言的一些习惯。 C语言中,使用0来表示 一月的话,不会像Java中这样令人困扰 ,本座会觉得理所当然的 Java这样搞,本座觉得有点坑人。

小S

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands

 
Recent comments
2017年4月~2019年4月垃圾短信排行榜Posted at:Thu Sep 26 04:51:48 2024
Qt5.7文档翻译:QWebEngineCookieStore类,QWebEngineCookieStore ClassPosted at:Fri Aug 11 06:50:35 2023盲盒kill -9 18289 Grebe.20230517.211749.552.mp4