String与Date格式之间的转换
【代码】String与Date格式之间的转换。
文章共83字 · 阅读需要大约1分钟
一键AI生成摘要,助你高效阅读
问答
·
1.string格式转化为Date对象
public Date format(String date){
DateFormat fmt =new SimpleDateFormat("yyyy-MM-dd");
Date date1=null;
try {
//String转date
date1 = fmt.parse(date);
} catch (ParseException e) {
// e.printStackTrace();
}
return date1;
}
2.Date格式转化为String对象
Date date=new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String startTime = sdf.format( date.getTime());
System.out.println(startTime);
更多推荐
已为社区贡献2条内容
所有评论(0)