Reactjs,如何使用moment.js是介于两者之间的。

问题描述 投票:0回答:1

我有这个数组。

["2018-01", "2018-02", "2018-03", "2018-04", "2018-05", "2018-06", "2018-07", "2018-08"]

这段代码应该是用来检测一个日期是否在启动时间之间,但却没有用。

array.forEach(function(item){
            //console.log(item)
            var a = moment(item);
            var start = a.format('YYYY-MM-DD')
            var b = a.add(30, 'days');
            var end = b.format('YYYY-MM-DD')


            console.log("procesing search between date : ",start , " and last date: ", end)
            letrado.forEach((value, key) => {
                //console.log("1-key =>", key, "1-value =>", value.compra_fecha_oper);
                let polo = moment(value.compra_fecha_oper).format('YYYY-MM-DD')

                var tonto = moment(polo).isBetween(String(start), String(end) ); // true
                if ( tonto = true ){
                    console.log(key, " Value Date: ",value.compra_fecha_oper ,"Has result: ",  tonto)

                }

            });

          });

结果是一个很长的列表,像这样。

enter image description here

但是,如果你尝试这样的概念,

      var isbetween = moment('2015-05-15').isBetween('2015-05-01', '2015-05-31');
      console.log("valor de isbetwen",isbetween )

是工作。

代码有什么问题?

javascript reactjs date momentjs
1个回答
1
投票

这一行是问题所在。

if ( tonto = true ){

这应该是三倍于

if ( tonto === true ){ 
/* or simply */ 
if ( tonto ){
© www.soinside.com 2019 - 2024. All rights reserved.