时间类型转换 String,Date

版权声明:帅气Dee海绵宝宝 独家放送 https://blog.csdn.net/xyjcfucdi128/article/details/82842389

 时间类型转换 Date--->String

private Date collectTime;
private String stringDateTime;

public String getStringDateTime(){
		String dateStr = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(collectTime);
		return dateStr;
}

时间类型转换 String--> Date

private Date collectTime;
private String stringDateTime;

public String getCollectTime(){
        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
        Date date = sdf.parse(stringDateTime);
		return date;
	}

猜你喜欢

转载自blog.csdn.net/xyjcfucdi128/article/details/82842389