hahaer1234
发贴: 3
积分: 0
|
于 2005-04-13 15:24
小弟java初学,今天碰到一个不解的问题,向各位大虾请教,请不吝赐教 我在用Date类的时候,遇到这样一种现象,当我使用GetDay()方法的时候,如果调用方法的对象是系统默认时间的对象,得出来的星期几结果是正确的,如果是我指定时间定义的对象调用,则得出的星期几的结果不正确,请问这是怎么回事?是我的语法写的不对,还是和系统的配置或者OS有关呢? 谢谢
所写代码如下:
import java.util.*;
public class DayTest { public static void main(String[] args) { Date date1=new Date(); Date date2=new Date(2005,4,13); int week1=date1.getDay(); int week2=date2.getDay(); System.out.println("The Time1 is:"+(date1.getYear()+1900)+(date1.getMonth()+1)+date1.getDate()+ " The Week1 is:"+week1); System.out.println("The Time2 is:"+date2.getYear()+date2.getMonth()+date2.getDate()+ " The Week2 is:"+week2); } }
结果如下: The Time1 is 2005413 The Week1 is:3 The Time2 is 2005413 The Week2 is:6
|