美美的小程序开发之路--20190411

2019-04-11  本文已影响0人  原鸣清
实战篇(零)

const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  // let ymdArray = [year, month, day]
  // let ymdStr = ymdArray.map(maggieNumber).join('/');

  let yearStr = maggieNumber(year)
  let monthStr = maggieNumber(month)
  let dayStr = maggieNumber(day) 

  let ymdStr = yearStr + "/" + monthStr + "/" + dayStr 

  let hourStr = maggieNumber(hour)
  let minuteStr = maggieNumber(minute)
  let secondStr = maggieNumber(second)

  let hmsStr = hourStr + ":" + minuteStr + ":" +secondStr
  
  return ymdStr + ' ' + hmsStr
}

const maggieNumber = n => {
  if (n > 9) {
    return n.toString()
  } else {
    return '0' + n.toString()
  }
  // n = n.toString()
  // return n[1] ? n : '0' + n
}

module.exports = {
  formatTime: formatTime
}


<!--logs.wxml-->
<view class="container log-list">
  <block wx:for="{{logs}}" wx:for-item="log">
    <text class="log-item">{{index + 1}}. {{log}}</text>
  </block>
</view>


.log-list {
  display: flex;
  flex-direction: column;
  padding: 40rpx;
}
.log-item {
  margin: 10rpx;
}
上一篇下一篇

猜你喜欢

热点阅读