321 日 , 2022 12:05:57
前端Js读取Excel的日期变为数字,日期格式转换

Excel的日期是以1900-1-0开始计算的,既1900-1-1就是1天;Js的Date是以1970-1-1 08:00:00开始的。
如EXcel中时间2022/1/1 1:00,Js导入后会变为44562.041666666664,就需要一个时间转换。

方法如下,其中dateFormat为转换时间为特定格式。

formatExcelDate(numb) {
  const old = numb - 1;
  const t = Math.round((old - Math.floor(old)) * 24 * 60 * 60);
  const time = new Date(1900, 0, old, 0, 0, t)
  return dateFormat(time)
}
724 日 , 2021 19:29:15
new Date()时间格式化在IOS不兼容情况

在开发微信小程序时,需要对后端返回的时间进行计算,得用new Date()先格式化时间,在安卓和微信开发工具测试没问题,但IOS出错,原因是因为IOS系统不支持以“-”分隔的日期格式。

let date ='2021-01-01 00:00:00';
console.log(new Date(date).getTime());

如上代码在苹果微信小程序中就无法显示。

 

解决方法,使用正则替换日期中的“-”为“/”。

let date ='2021-01-01 00:00:00';
date = date.replace(/-/g, '/');
console.log(new Date(date).getTime());

 

 

 

720 日 , 2021 13:50:24
Js驼峰命名和下划线命名转换

驼峰命名法(CamelCase)和下划线命名法(UnderScoreCase)是常用的变量或方法命名方法。有些时候可能会需要转换,方法如下:

//驼峰转换下划线
function camelToUnderline(str) {
  return str.replace(/([A-Z])/g,"_$1").toLowerCase()
}
//下划线转换驼峰 
function underlineToCamel(str) { 
  return str.replace(/\_(\w)/g, (all,letter)=>letter.toUpperCase()) 
}

 

529 日 , 2021 15:28:09
yarn安装,报错node sass:Command failed.

在使用yarn安装项目时,报错node_modules\node sass:Command failed. 网上找到的可行解决方法如下:

npm install -g mirror-config-china --registry=http://registry.npm.taobao.org
npm install node-sass
yarn install
518 日 , 2021 10:01:13
Vue.prototype微信小程序模板无法读取挂载值

挂载到Vue.prototype的全局变量,在微信小程序中,无法在模板中直接读取xxx值(结果为undefined),只能在js中读取(HX 3.1.13,当前最新稳定版)。

这种挂载的方式,需要在根目录的main.js中进行,在页面中,我们可以使用this.xxx的形式获取变量,但是,在微信小程序模板无法读取挂在的值,只能在js中使用。

因此,实现全局变量推荐使用Vuex实现。

508 日 , 2021 13:53:53
Postman中文汉化

先从官网下载Postman,安装。再从github下载汉化包,具体操作详见github文档。需要注意的是Postman会自动更新,每次更新都需要重新下载对应汉化包,建议设置为禁止更新。

418 日 , 2021 16:00:34
测试服务器带宽脚本

在Linux服务器下,可以使用speedtest.py脚本测试带宽,测试后会生成一张在线结果图。这个Python脚本同样可以用于Windows系统测试,前提是安装了Python环境。

wget https://raw.github.com/sivel/speedtest-cli/master/speedtest.py
python speedtest.py --share

410 日 , 2021 18:55:53
Linux删除名字带反斜杠的文件或文件夹

之前在Windows服务器运行的Python项目,搬到Linux后,忘记修改文件保存路径的格式,导致文件名中带有反斜杠“\”,变成了“\upload\20210410\test.jpg”,直接rm删除不掉,得加”号,正确的命令是:

 rm '\upload\20210410\test.jpg'

 

404 日 , 2021 12:30:14
PHPCMS伪静态

PHPCMS伪静态的方法,如果使用宝塔或PHP Study,将以下代码复制到伪静态设置中即可。

location / {
  rewrite ^/(.*)content-([0-9]+)-([0-9]+)-([0-9]+)\.html /index.php?m=content&c=index&a=show&catid=$2&id=$3&page=$4;
  rewrite ^/(.*)show-([0-9]+)-([0-9]+)-([0-9]+).html /index.php?m=content&c=index&a=show&catid=$2&id=$3&page=$4;
  rewrite ^/(.*)list-([0-9]+)-([0-9]+).html /index.php?m=content&c=index&a=lists&catid=$2&page=$3;
}