//js隐藏姓名第二位
//js隐藏姓名第二位
this.user_name="白菜菜";
let username=this.user_name.split('');//字符串分割成字符串数组['白','菜','菜']
username.splice(1,1,"*");//['白','*','菜']
this.user_name=username.join('');//数组变字符串"白*菜"
//js隐藏姓名后两位
this.user_name = this.user_name.substr(0, 1)
+ new Array(this.user_name.length).join('*')
//substr截取字符串
//js写动态时间戳,效果如同健康码、行程码的动态时间变化效果
//format.js文件
export function getDate(datetime, startType) {
var date = new Date(datetime); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
var year = date.getFullYear(),
month = ("0" + (date.getMonth() + 1)).slice(-2),
sdate = ("0" + date.getDate()).slice(-2),
hour = ("0" + date.getHours()).slice(-2),
minute = ("0" + date.getMinutes()).slice(-2),
second = ("0" + date.getSeconds()).slice(-2);
// 拼接
// var result = year + "-"+ month +"-"+ sdate +" "+ hour +":"+ minute +":" + second;
// 返回
// return result;
let resStr = "";
if (startType === "year")
resStr =
year +
"-" +
month +
"-" +
sdate +
" " +
hour +
":" +
minute +
":" +
second;
if (startType === "day") resStr = year + "-" + month + "-" + sdate;
if (startType === "month") resStr = month + "-" + sdate;
if (startType === "hour") resStr = hour + ":" + minute + ":" + second;
return resStr;
}
//在引用的vue文件中
<view class="padding-top-sm">
<text style="font-size: 16px;">当前时间:{{clock|FormatTime}}</text>
</view>
<script>
import {getDate} from './format.js';
data() {
return {
val: '',
clock: Date.parse(new Date())
},
onLoad(e) {
let _this = this;
setInterval(function() {
_this.clock = Date.parse(new Date());
}, 1000);
},
filters: {
FormatTime: function(val) {
return getDate(val, "year");
},
},
</script>