Edingbrugh

导航

java时间处理工具

 

  package xxx.xxx

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
/**
*时间处理工具类
*/
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 将时间转换成为字符串类型
*/
public static String formatDate(Date date) throws ParseException{
return sdf.format(date);
}
/**
* 将字符串转换成时间的类型
*/
public static Date parse(String strDate) throws ParseException{
return sdf.parse(strDate);
}
}

注:将字符串转换成时间的类型必须要保存在方法上抛出Parseexception不然会一直报错

posted on 2019-07-25 13:55  Edingbrugh  阅读(59)  评论(0)    收藏  举报