Java中Timestamp与String之间的转化

1、Timestamp转String

public String changeTime(Timestamp time){
    if (null != time) {
        return new SimpleDateFormat("yyyy-MM-dd").format(time);
    } else {
        return "";
    }
}

2、String转Timestamp

public Timestamp changeDate(String time) throws Exception(){
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    if (StringUtils.isEmpty(time)) {
        return null;
    }
    Date date = sdf.parse(time);
    Timestamp ctime = new Timestamp(date.getTime());
    return ctime;
}

欢迎各位热爱学习的朋友加入Java技术交流大家庭(QQ群):422239489


版权声明:本文为m0_38137589原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。