当前位置:网站首页>Methods commonly used in uniapp (part) - timestamp problem and rich text parsing image problem

Methods commonly used in uniapp (part) - timestamp problem and rich text parsing image problem

2022-06-10 15:32:00 A wooden fish of austerity

Get the current date timestamp

/** *  Get the current timestamp  */
function time() {
    
  return Math.round(new Date() / 1000);
}

String to timestamp

/** *  String to timestamp  * @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);
}

Rich text parsing picture adding prefix or suffix ( Common and processing oss The image processing )

//  details 
richTxt = richTxt.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, (match, p1) => {
    
	return `<img src='${
      this.imgUrl()+p1 + '/okh710auto'}' style="max-width:100%"/>`;
});
原网站

版权声明
本文为[A wooden fish of austerity]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101522503014.html