1-1-8-14 如何使用时间函数的一问
发信人: silver.bbs@bbs.nankai.edu.cn (书剑走天涯), 信区: Java
标题: Re: 如何使用时间函数的一问
发信站: 我爱南开站 (Thu Oct 17 17:29:08 2002)
转信站: SMTH!maily.cic.tsinghua.edu.cn!news.happynet.org!NanKai
y用import java.util.Calendar;试试
我的一个测试小程序:
Calendar c = Calendar.getInstance();
Date t1 = c.getTime();//当前时间
System.out.println(" current time : "+t1);
c.add(Calendar.DATE,1);//Date Arithmetic function.取一天后
Date tt = c.getTime();//一天后的当前时间
System.out.println(" time after a day : "+tt);
在jb6中运行的结果是:
current time : Thu Oct 17 17:25:28 CST 2002
time after a day : Fri Oct 18 17:25:28 CST 2002
在时间片来说可能会有在运行顺序上会有一些时间的差距.
不过偶觉得可以忽略吧...
如果偶理解错误就请扔板砖吧//bow
【 在 ahdoh (小辉) 的大作中提到: 】
: 比如 当前时间
: Date nowDate= new Date()
: 那如何判断一天以后的此刻?即 nowDate+(1天) 如何表示?
: 我看了文档不是很明白 大侠指点一下。
发信人: silver.bbs@bbs.nankai.edu.cn (书剑走天涯), 信区: Java
标题: Re: 如何使用时间函数的一问
发信站: 我爱南开站 (Thu Oct 17 17:30:55 2002)
转信站: SMTH!maily.cic.tsinghua.edu.cn!news.happynet.org!NanKai
参看jdk源码里面Calendar对这个function的解释:
/**
* Date Arithmetic function.
* Adds the specified (signed) amount of time to the given time
field,
* based on the calendar's rules. For example, to subtract 5 days
from
* the current time of the calendar, you can achieve it by calling:
* <p>add(Calendar.DATE, -5).
* @param field the time field.
* @param amount the amount of date or time to be added to the
field.
*/
应该是没有问题的...:)
best wishes
【 在 silver (书剑走天涯) 的大作中提到: 】
:y用import java.util.Calendar;试试
:我的一个测试小程序:
: Calendar c = Calendar.getInstance();
: Date t1 = c.getTime();//当前时间
: System.out.println(" current time : "+t1);
: c.add(Calendar.DATE,1);//Date Arithmetic function.取一天后
: Date tt = c.getTime();//一天后的当前时间
: System.out.println(" time after a day : "+tt);
: 在jb6中运行的结果是:
:current time : Thu Oct 17 17:25:28 CST 2002
: .................(以下省略)
页:
[1]