黑马程序员技术交流社区
标题:
关于获取日期的问题
[打印本页]
作者:
谢威
时间:
2013-7-18 11:45
标题:
关于获取日期的问题
本帖最后由 谢威 于 2013-7-18 12:15 编辑
这段代码所获取的星期与正常的星期差1,这是是为什么?
import java.util.*;
import java.text.*;
class CalendarDemo
{
public static void main(String[] args)
{
Calendar c = Calendar.getInstance();
String[] mons = {"一月","二月","三月","四月"
,"五月","六月","七月","八月"
,"九月","十月","十一月","十二月"};
String[] weeks = {"","星期日","星期一","星期二","星期三","星期四","星期五","星期六",};
int index = c.get(Calendar.MONTH);
int index1 = c.get(Calendar.DAY_OF_WEEK);
sop(c.get(Calendar.YEAR)+"年");
//sop(c.get(Calendar.MONTH)+1+"月");
sop(mons[index]);
sop(c.get(Calendar.DAY_OF_MONTH)+"日");
sop("星期"+c.get(Calendar.DAY_OF_WEEK));
}
public static void sop(Object obj)
{
System.out.println(obj);
}
}
复制代码
作者:
张云杰
时间:
2013-7-18 11:50
String[] weeks = {"","星期日","星期一","星期二","星期三","星期四","星期五","星期六",};
多了一个拉
作者:
yinjiek
时间:
2013-7-18 12:04
你声明的weeks数组没用上!是这样才对 sop(weeks[index1]);
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2