date和string转换用joda包

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.util.Date;

/**
* Created by Administrator on 2019/3/25.
*/
public class datatimeutil {
public static Date strtodate(String datetimestr, String formatestr){
DateTimeFormatter dateTimeFormat= DateTimeFormat.forPattern(formatestr);
DateTime dateTime=dateTimeFormat.parseDateTime(datetimestr);
return dateTime.toDate();
}
public static String datetostr(Date date, String formatestr){
if(date==null){
return "";
}
DateTime dateTime=new DateTime(date);
return dateTime.toString(formatestr);
}
}
posted @ 2019-06-21 09:20  黑魔法os  阅读(719)  评论(0编辑  收藏  举报