Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 编程/算法/API  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 问一个Date类的奇怪问题
hahaer1234





发贴: 3
积分: 0
于 2005-04-13 15:24 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
小弟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




话题树型展开
人气 标题 作者 字数 发贴时间
6509 问一个Date类的奇怪问题 hahaer1234 740 2005-04-13 15:24
5003 Re:问一个Date类的奇怪问题 cxp108 103 2005-04-13 18:15
4876 Re:问一个Date类的奇怪问题 why 698 2005-04-13 20:37
5320 Re:问一个Date类的奇怪问题 hahaer1234 12 2005-04-14 07:58

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923