方法一
前端显示:2020-11-18T22:42:48.000+00:00
实体类加上注解
@JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date chargeTime;
结果:
2020-11-19 06:42:18
方法二
前端传入参数转换
function renderTime(date) {
var dateee = new Date(date).toJSON();
return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
}
结果:
2020-11-19 06:42:18
实体类写了个方法没派上用场
public String Time(Date date){
SimpleDateFormat df = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
String Time=df.format(date);
return Time;
}
接收到2020-12-30T19:26中间有T把T去除
String time= request.getParameter("time");
time = time.replaceAll("T"," " );
System.out.println("time="+time);
输出
2020-12-30 19:26
去除别的
利用正则表达式匹配字母,然后替换
public class Test {
public static void main(String[] args) {
String str = "asdasasdkdlsdaa668*)(^%*YTILKHqwe12345jfkhkab";
str = str.replaceAll("[a-zA-Z]","" );
System.out.println(str);
}
}
输出的结果:
668*)(^%*12345
版权声明:本文为qq_42981242原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。