Topic: 请教日期型数据运算

  Print this page

1.请教日期型数据运算 Copy to clipboard
Posted by: zhangjiyh
Posted on: 2004-12-06 16:29

我想运算求出当前日期和指定日期的相差天数
还有指定日期加上一定天数后的新日期
如何编写阿?请教……

2.Re:请教日期型数据运算 [Re: zhangjiyh] Copy to clipboard
Posted by: littledeer1974
Posted on: 2004-12-06 16:37

e373. Getting the Current Date
Calendar cal = new GregorianCalendar();

// Get the components of the date
int era = cal.get(Calendar.ERA); // 0=BC, 1=AD
int year = cal.get(Calendar.YEAR); // 2002
int month = cal.get(Calendar.MONTH); // 0=Jan, 1=Feb, ...
int day = cal.get(Calendar.DAY_OF_MONTH); // 1...
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); // 1=Sunday, 2=Monday, ...


http://javaalmanac.com/egs/java.util/GetCurDate.html

下边是生成你自己的Calendar的对象,然后应该做简单的运算就可以实现你的要求了吧,我想

Calendar xmas = new GregorianCalendar(1998, Calendar.DECEMBER, 25);
Date date = xmas.getTime();

3.Re:请教日期型数据运算 [Re: zhangjiyh] Copy to clipboard
Posted by: zhangjiyh
Posted on: 2004-12-06 19:25

谢谢 我会尝试的 不过怎么感觉比C++麻烦了阿 嘿嘿 不知道有没有现成的日期运算函数的


   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