WXS 语言 date日期获取,安卓正常,IOS不正常问题
发布于 6 年前 作者 junshi 6221 次浏览 来自 问答

<!-- 运算两个时间得差值–>

<wxs module=“datetiming”>

    var dateResult = function (d,shopperTime) {

      var result = “”;

      if(shopperTime==null){

        var newDate = getDate(); //返回当前时间对象

      } else {

        var newDate = getDate(shopperTime); //返回时间

        result = “用时:”;

      }

      var payDate = getDate(d);

      console.log(“当前时间:”+newDate)

      console.log(“支付时间:”+payDate)

      var payDateResult = Math.round(payDate.getTime()/1000);

      var newDateResult = Math.round(newDate.getTime()/1000);

      console.log(“当前时间:”+newDateResult)

      console.log(“支付时间:”+payDateResult)

      var resultDate = newDateResult - payDateResult;

      var h = Math.floor(resultDate / 3600);

      var m = Math.floor((resultDate / 60 % 60));

      var s = Math.floor((resultDate % 60));

      console.log(“最终时间:”+result + h + “时” + m + “分” + s + “秒”)

       return newDateResult;

    };

    module.exports = {

      dateResult : dateResult

    }

  </wxs>

安卓一切正常显示。 IOS系统全部是NaN时NaNNaN秒。。

求大神解答~ 如何出里。。目前调试很难。。

    我经过测试得出问题出在: getDate(shopperTime);

              如果直接: getDate(); 可以得到时间。但是我现在需要自定义时间。

3 回复

// ios 日期格式为2017/05/06 12:10:30

    var date = times ? getDate(times.replace(getRegExp(’-’, ‘g’), ‘/’)) : getDate();

    var year = date.getFullYear();

    var month = date.getMonth() + 1;

    var day = date.getDate();

    var hour = date.getHours();

    var minute = date.getMinutes();

    var second = date.getSeconds();

    format = format || ‘YYYY/MM/DD HH:mm:ss’;

    [year, month, day, hour, minute, second] = [year, month, day, hour, minute, second].map(function(n) {

        n = n.toString();

        return n[1] ? n : ‘0’ + n;

    });

    return format.replace(‘YYYY’, year).replace(‘MM’, month).replace(‘DD’, day)

        .replace(‘HH’, hour).replace(‘mm’, minute).replace(‘ss’, second);

我也遇到了,你找到原因了吗

一楼镇楼。求大神给解决~ 。谢谢

回到顶部