java 日期范围

来源:百度知道 编辑:UC知道 时间:2024/09/28 10:20:17
也就是说要实现我给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));