0
点赞
收藏
分享

微信扫一扫

日期格式相互转换

zmhc 2022-05-06 阅读 86

日期格式互转

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

/**
 * @author ZhangZZ
 * @Create 2022-04-04 10:17
 */
public class DateMapperHMS {
    public String dateToString(Date date) {
        return date != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(date) : null;
    }

    public Date stringToDate(String date) {
        try {
            return date != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                    .parse(date) : null;
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}
举报

相关推荐

0 条评论