获取当前日期时间戳
/**
* 获取当前时间戳
*/
function time() {
return Math.round(new Date() / 1000);
}
字符串转时间戳
/**
* 字符串转时间戳
* @example: time:2022-01-12 12:00:00
*/
function stringTotime(time) {
let time_sub= time.substring(0, 19);
time_sub= time_sub.replace(/-/g, "/");
return Math.round(new Date(time_sub).getTime() / 1000);
}
富文本解析图片添加前缀或后缀(常用与处理oss图片处理)
// 详情
richTxt = richTxt.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, (match, p1) => {
return `<img src='${this.imgUrl()+p1 + '/okh710auto'}' style="max-width:100%"/>`;
});
- 利用
.replace()
(方法用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串。) - 参看文档 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/replace