微信小程序 wxs、js使用正则替换字符串

案例

把 2020-8-3 18:18:23 中的" - "替换为"/"

js用法:

var str ='2020-8-3 18:18:23';
//以下两种任选一种
str.replace(new RegExp('-','g'),'/');
str.replace(/-/g,'/');

console.log(str);

wxs用法:

var datewxs=function(str){
    var newdate = str.replace(getRegExp('-','g'),'/');
    return newdate;
}

module.exports = {
  datewxs: datewxs
}



<!--wxml引用-->
<wxs module="datewxs" src="../../utils/datewxs.wxs"></wxs>
<view>{{datewxs.datewxs('2020-8-3 18:18:23')}}</view>

输出为

2020/8/3 18:18:23

 

posted @ 2020-08-03 18:28  於生  阅读(2766)  评论(0编辑  收藏  举报