永发信息网

java 日期范围

答案:2  悬赏:60  手机版
解决时间 2021-02-20 11:48
也就是说要实现我给2个参数,比如20080531,20080930 ,然后java可以自动实现将其拆成20080531-20080630......之类的安每月为周期组成的时间段
最佳答案
import java.util.Date;

public class TimeSpan
{
public final static TimeSpan ZERO = new TimeSpan(0);

private long _totalMilliSeconds = 0;

public TimeSpan(long totalMilliSeconds)
{
_totalMilliSeconds = totalMilliSeconds;
}

public TimeSpan(Date afterDate, Date beforeDate)
{
this(afterDate.getTime() - beforeDate.getTime());
}

public long getMilliSeconds()
{
return _totalMilliSeconds;
}
public long getSeconds()
{
return Math.round(_totalMilliSeconds/1000);
}
public long getMinutes()
{
return Math.round(_totalMilliSeconds/(1000*60));
}
public long getHours()
{
return Math.round(_totalMilliSeconds/(1000*60*60));
}
}
全部回答
setdate()函数写的有问题,这个函数最多只会等到当前日期,而且上下两个函数没有关系,string birthday = df.format(date);这句话只是定义了一个局部变量,类里边的示例变量没有赋值,而你在showmess()里又使用了(this.birthday),所以就会输出空。试着这样改: public class maindate{ public static void main(string[] args){ testdate td=new testdate(); td.setdate("2008-08-08"); td.showmess();//可正常输出 td.setdate("2008 08 08"); td.showmess();//输出“出生日期未设置或为空” } } class testdate{ private string birthday; public void setdate(string strdate) { dateformat df = new simpledateformat("yyyy-mm-dd"); try{ date tmpdate = df.format(strdate);//如果出异常,则参数strdate格式不对,不执行下句 this.birthday=strdate; }catch(parseexception pe){ //... } } public void showmess() { //... if(this.birthday!=null||!"".equals(this.birthday)){ system.out.println("出生日期:"+this.birthday); }else{ system.out.println("出生日期未设置或为空"); } } } 以上程序请自行测试
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
bed和he丨p发音是否相同
怎么做车间现场检查问题点图示表格
黄土密度是多少
证券基金机构监管部主要负责()。A.制定有关证
广电网络麒麟西路营业厅在什么地方啊,我要过
2014年的假期安排为什么除夕不是国家法定节假
D.生态系统中的组成成分越多,食物网越复杂,生
长安悦翔车门底下那块铁皮刮坏了
老坝港幼儿园我想知道这个在什么地方
六合在长江的北面还是南面在南京的是不是在南
distinguish yourself in battle什么意思
没当上皇帝的阿哥做什么
电压力锅要离煤气灶多远安全
求(x^2+(1/3)^2)^15展开中含x^5的项,常数项及
怎么看自己电脑多少寸
推荐资讯
写严厉的老师,四百字作文。
耿马傣族佤族自治县农村信用合作联社孟定信用
秦殇:彭城的几个任务
解一元二次方程的步骤是什么?
材料一在拿破仑的灵柩穿过凯旋门45年之后的18
笔记本电脑在开机的时候光驱部分为什么要响一
下列属于生产成本的是()。A.制造费用B.管理
一分的利息是什么意思?十万元一年多少钱利息
华宇通讯怎么去啊,有知道地址的么
为什么我的sm g5306w开不了4g网
梅林饭店这个地址在什么地方,我要处理点事
佰仟金融员工参加哪些培训
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?