1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>使用Vue格式化日期</title>
    8. <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.js"></script>
    9. </head>
    10. <script>
    11. window.onload = function(){
    12. var app = new Vue({
    13. el: '#app',
    14. data:{
    15. timeMes:""
    16. },
    17. created() {
    18. let self = this;
    19. self.timeMes = self.dataFormat(new Date(1522611151000))
    20. new Date(element.followTime)
    21. },
    22. methods:{
    23. dataFormat(time){
    24. return `${time.getFullYear()}-${time.getMonth() + 1 >= 10 ? (time.getMonth() + 1) : '0' + (time.getMonth() + 1)}-${time.getDate() >= 10 ? time.getDate() : '0' + time.getDate()}
    25. ${time.getHours() >= 10 ? time.getHours() : '0' + time.getHours()} : ${time.getMinutes()>=10?time.getMinutes():'0'+time.getMinutes()} : ${time.getSeconds() >= 10 ? time.getSeconds() : '0' + time.getSeconds()}`;
    26. }
    27. }
    28. })
    29. }
    30. </script>
    31. <body>
    32. <div id="app">
    33. 时间:{{timeMes}}
    34. </div>
    35. </body>
    36. </html>

    “通话时长”的这种时间:

    timeDeal(time) {   // time 是一个时间戳
      const timer = +time;
      const minutes = Math.floor(timer / 60);
      const seconds =
            (timer % 3600) % 60 > 9
      ? (timer % 3600) % 60
      : `0${(timer % 3600) % 60}`;
    
      return `${minutes}'${seconds}''`;
    }