1. 将Java 字符串转化为Date
2. 将Java类里面的Date转成String
public static String getDateStrToTime(String time) {
String timeBegin;
//1. 字符串转化为Date
SimpleDateFormat sdf = new SimpleDateFormat(dateFormatYMDofyyyy);
Date date;
try {
date = sdf.parse(time);
//2. Date转成String
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatYMDofChinese);
timeBegin = simpleDateFormat.format(date);
Log.d("getDateStr", "timeBegin: " + timeBegin);
} catch (ParseException e) {
e.printStackTrace();
timeBegin = "";
}
return timeBegin;
}
* @param time 20220101
* @return 2022年01月01日
网友评论