iLeichun

当前位置: 首页 > Java

Java中日期转换、加减

分类:Java   来源:网络   时间:2010-11-20 14:48:10

package com.youwei.common;

import java.text.*;
import java.util.*;

public class CDate {
public static Date toDate(String cDate) throws ParseException {
SimpleDateFormat fmt = new SimpleDateFormat(”yyyy-MM-dd”);
return fmt.parse(cDate);
}

public static Date changeDay(Date date, int offset) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_YEAR,
(calendar.get(Calendar.DAY_OF_YEAR) + offset));
return calendar.getTime();
}
}

 

更多