天道不一定酬所有勤
但是,天道只酬勤

时间的遍历

public Calendar getDate(String dateString){  
        int year = Integer.parseInt(dateString.substring(0,dateString.indexOf("-")));  
        int mounth =  Integer.parseInt(dateString.substring(dateString.indexOf("-")+1,dateString.lastIndexOf("-")));  
        int day = Integer.parseInt(dateString.substring(dateString.lastIndexOf("-")+1,dateString.lastIndexOf(" ")));  
        int hour  = Integer.parseInt(dateString.substring(dateString.lastIndexOf(" ")+1,dateString.indexOf(":")));  
        int minutes  = Integer.parseInt(dateString.substring(dateString.indexOf(":")+1,dateString.lastIndexOf(":")));  
        int second  = Integer.parseInt(dateString.substring(dateString.lastIndexOf(":")+1));  
        Calendar date = Calendar.getInstance();  
        date.set(year, mounth-1, day ,hour,minutes,second);  
        return date;  
    }  

Calendar beginDate = getDate("2014-12-31 12:00:00");  
Calendar endDate = getDate("2015-1-31 12:00:00");  
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
while (beginDate.compareTo(endDate) <= 0) {  
    String currentString = sdf.format(beginDate.getTime());  
    sysout(currentString);  
    beginDate.set(Calendar.DATE, beginDate.get(Calendar.DATE) + 1);  
}  
(全文完)
欢迎关注HollisChuang微信公众账号
打赏

如未加特殊说明,此网站文章均为原创,转载必须注明出处。HollisChuang's Blog » 时间的遍历

分享到:更多 ()

HollisChuang's Blog

联系我关于我