Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Dayjs返回数字,而不是带有“.form”的相对单词`_Javascript_Dayjs - Fatal编程技术网

Javascript Dayjs返回数字,而不是带有“.form”的相对单词`

Javascript Dayjs返回数字,而不是带有“.form”的相对单词`,javascript,dayjs,Javascript,Dayjs,dayjs()上有一个插件将返回人类可读的字符串,而不是数字。有没有办法只返回号码 像这样的 dayjs('2020-07-1')。from(dayjs('2020-07-9'))/-8 dayjs('2020-07-1')。从(dayjs('2020-07-1'))//0 dayjs('2020-07-11')。从(dayjs('2020-07-9'))//2 没有dayjs我可以建议一种简单的方法来获得你想要的结果,如下所示 函数getDayDifference(从,到){ 设diffin

dayjs()上有一个插件将返回人类可读的字符串,而不是数字。有没有办法只返回号码

像这样的

dayjs('2020-07-1')。from(dayjs('2020-07-9'))/-8
dayjs('2020-07-1')。从(dayjs('2020-07-1'))//0
dayjs('2020-07-11')。从(dayjs('2020-07-9'))//2

没有
dayjs
我可以建议一种简单的方法来获得你想要的结果,如下所示

函数getDayDifference(从,到){ 设diffinmillizes=new Date(from)-new Date(to); //除以(1000*60*60*24)得到天数差。 设天数=数学整数(diffinmillizes/(1000*60*60*24)); 控制台日志(天); 返程天数; } getDayDifference('2020-07-1','2020-07-9');//-8. getDayDifference('2020-07-1','2020-07-1');//0
getDayDifference('2020-07-11','2020-07-9');//2没有
dayjs
我可以建议一种简单的方法来获得你想要的结果,如下所示

函数getDayDifference(从,到){ 设diffinmillizes=new Date(from)-new Date(to); //除以(1000*60*60*24)得到天数差。 设天数=数学整数(diffinmillizes/(1000*60*60*24)); 控制台日志(天); 返程天数; } getDayDifference('2020-07-1','2020-07-9');//-8. getDayDifference('2020-07-1','2020-07-1');//0 getDayDifference('2020-07-11','2020-07-9');//2工作代码

使用
dayjs
库中的
diff()
方法,并将
'day'
作为第二个参数

console.log(dayjs('2020-07-1').diff('2020-07-9','day');//-8.
console.log(dayjs('2020-07-1').diff('2020-07-1','day');//0
console.log(dayjs('2020-07-11').diff('2020-07-9','day');//2
工作代码

使用
dayjs
库中的
diff()
方法,并将
'day'
作为第二个参数

console.log(dayjs('2020-07-1').diff('2020-07-9','day');//-8.
console.log(dayjs('2020-07-1').diff('2020-07-1','day');//0
console.log(dayjs('2020-07-11').diff('2020-07-9','day');//2

使用moment.jsinstead@chiliNUT对我来说太大了~使用moment.jsinstead@chiliNUT对我来说太大了~