wxs 语法如何 把 2021-03-17 17:03:31 时间转换成时间戳呢?

发布于 5 年前作者 dfeng9064 次浏览最后编辑 5 年前来自 ask

wxs 语法如何 把 2021-03-17 17:03:31  时间转换成时间戳呢?

4 回复
pingfu
pingfu1 楼5 年前

wxs文件里

function formatTime(str) {

  if (str == null) {

    return;;

  } else {

    var timeStr = getDate(str).getTime();

    return timeStr;

  }

}

module.exports = {

  formatTime: formatTime

}

wxml文件里

<wxs src="tool.wxs" module="tools" />

{{tools.formatTime(你的时间参数)}}

<view>{{tools.formatTime("2021-03-17 17:03:31")}}</view>


weilei
weilei3 楼5 年前
  var dealTime = function(timeString){
    var date = getDate(timeString)
    return date.getTime()
  }
  module.exports = {
    dealTime:dealTime
  }

  {{test.dealTime('2021-03-17 17:03:31 ')}}
  

https://developers.weixin.qq.com/miniprogram/dev/reference/wxs/06datatype.html

yangzhu
yangzhu4 楼7 个月前

有大佬不