前端时间格式2020-11-18T22:42:48.000+00:00 转化成正常格式

方法一
前端显示: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

  • 11
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值