java将输入的字符串时间提前一天,再以字符串形式输出

2017-04-26     浏览次数:

输入一个字符串时间后,程序将该时间提前一天后,再以字符串的形式输出
* 输入时间格式为:yyyy-MM-dd
     * */
    public String timeSub(String time){
        String year = time.substring(0,4);
        String monts = time.substring(5,7);
        String day = time.substring(8);
        int ye = Integer.parseInt(year);
        int mo = Integer.parseInt(monts);
        int da = Integer.parseInt(day);
        if(da != 1){
            da = da-1;
            if(da<10){
                time=year+"-"+monts+"-0"+da;
                return time;
            }else{
                time=year+"-"+monts+"-"+da;
                return time;
            }
        }else{
            da=30;
            if(mo != 1){
                mo = mo-1;
                if(mo < 10){
                    time = year+"-0"+mo+"-"+da;
                    return time;
                }else{
                    time=year+"-"+mo+"-"+da;
                    return time;
                }
            }else{
                mo=12;
                ye=ye-1;
                time=ye+"-"+mo+"-"+da;
                return time;
            }
        }
    }
}
*转载请注明出处,更多资料尽在 吾爱编程
返回吾爱编程首页