年月日与time的相互转换

年月日的转换#


// 这里就是把时间格式化成你要的
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");//将时间转换为年
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//将时间转换为年月日时分秒
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//将时间转化为年月日
String result = sdf.format(time); 

//将日期转换为时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dt2 = sdf.parse(date);
return dt2.getTime();
原创作品,转载请注明出处!
原文地址:https://www.cnblogs.com/yidijimao/p/5728286.html