时间戳格式化

按照YYYY-MM-DD HH:mm:ss格式化时间

<template>
  <div></div>
</template>
<script>
export default{
  created() {
    this._getDate()
  },
  methods: {
    _getDate() {
      let now = new Date()
      console.log('now', now)
      let year = now.getFullYear()
      let month = now.getMonth() + 1
      let day = now.getDate()
      let hour = now.getHours()
      let minutes = now.getMinutes()
      let seconds = now.getSeconds()
      let time = year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds
      console.log(time)
    }
  }
}
</script>

posted @ 2018-03-23 15:39  海螺呜呜  阅读(762)  评论(0编辑  收藏  举报