1.reduce() 方法接收一个函数作为累加器,数组中的每个值(从左到右)开始缩减,最终计算为一个值
reduce([65, 44, 12, 4]);
1.https://itbilu.com/nodejs/npm/VkCir3rge.html#parse-init
2.https://itbilu.com/nodejs/npm/EJlmbFhgg.html
获得今天、明天和昨天的日期。
let today = moment(new Date());
let tomorrow = moment(new Date()).add(1,'days');
let yesterday = moment(new Date()).add(-1, 'days');
1.用 fs 模块的 access,当然还有其他也能用,后续可以多看看
isFileExit(url) {
return new Promise(function(resolve, reject) {
fs.access(url, err => {
if (err) {
reject(false);
} else {
resolve(true);
}
});
});
}
1.视频音频图片处理 2.有 ffmpeg,ffplay,ffprode 可用,这边用的是 ffmpeg -i ,详情可以去官网看
getVideoTime(url) {
const ffmpeg = utils.config('bin_ffmpeg');
exec(ffmpeg + ' -i ' + url, function(err, stdout, stderr) {
const outStr = stderr.toString();
const regDuration = /Duration\: ([0-9\:\.]+),/;
const rs = regDuration.exec(outStr);
if (rs[1]) return rs[1];
});
return '';
}
1.如果有个字段不能为空又未设置默认值需要把改字段加进去,如这边需要加个 project_id
INSERT INTO `assets` ( `id`, `video_time` )
VALUES
( 3693, 22 ),
( 3691, 22 )
ON DUPLICATE KEY UPDATE `id` =
VALUES
( `id` ),
`video_time` =
VALUES
(
`video_time`)
2.通过 INNER JOIN ON
UPDATE AA AS aa
INNER JOIN BB AS bb ON bb.id = aa.asset_id
SET aa.asset_created_at = FROM_UNIXTIME( bb.created_at, '%Y-%m-%d' )
WHERE
aa.id >= 362904105
AND aa.id <= 362914104
1.时间戳转换成日期 FROM_UNIXTIME(time,"%Y-%m-%d")
2.把日期转换为时间戳 UNIX_TIMESTAMP('2015-04-15')
SELECT * FROM article WHERE
title REGEXP "车|摩托|红色|美国|2006"
1.array_except 函数从数组中删除给定的键 /值对
$array = ['name' => 'Desk', 'price' => 100];
$filtered = array_except($array, ['name']);
dd($filtered);
array:1["price"=>100]
1.$table->date('asset_create_at')->nullable(true)->comment = '素材上传时间';
2.当设置时间为空时不能用 default 。
1.array_flip() 函数用于反转 /交换数组中所有的键名以及它们关联的键值。
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$result=array_flip($a1);
print_r($result);
Array ( [red] => a [green] => b [blue] => c [yellow] => d )
1.list() 函数用于在一次操作中给一组变量赋值
<?php
$my_array = array("Dog","Cat","Horse");
list($a, $b, $c) = $my_array;
echo "I have several animals, a $a, a $b and a $c.";
?>
<?php
$firstname = "Peter";
$lastname = "Griffin";
$age = "41";
$result = compact("firstname", "lastname", "age");
print_r($result);
?>
Array ( [firstname] => Peter [lastname] => Griffin [age] => 41 )
<?php
// 表示由数据库返回的可能记录集的数组
$a = array(
array(
'id' => 5698,
'first_name' => 'Bill',
'last_name' => 'Gates',
),
array(
'id' => 4767,
'first_name' => 'Steve',
'last_name' => 'Jobs',
),
array(
'id' => 3809,
'first_name' => 'Mark',
'last_name' => 'Zuckerberg',
)
);
$last_names = array_column($a, 'last_name');
print_r($last_names);
?>
Array
(
[0] => Gates
[1] => Jobs
[2] => Zuckerberg
)
1
Oktfolio 2021-10-29 17:05:44 +08:00
Moment.js is a legacy project, now in maintenance mode.
|
2
simple233 2021-10-29 17:45:06 +08:00
建议用 dayjs 处理时间
|
4
shilianmlxg 2021-10-29 23:39:40 +08:00
谢谢大佬 可以多学亿点点
|