How to convert unix timestamp to calendar date moment.js

前端 未结 11 1969
遥遥无期
遥遥无期 2020-12-22 21:36

I have a unix timestamp, and I\'m trying to convert it into a calendar date such as MM/DD/YYYY. So far, I have this:



        
相关标签:
11条回答
  • 2020-12-22 22:03
    moment(timestamp).format('''any format''')
    
    0 讨论(0)
  • 2020-12-22 22:03

    I fixed it like this example.

    $scope.myCalendar = new Date(myUnixDate*1000);
    <input date-time ng-model="myCalendar" format="DD/MM/YYYY" />
    
    0 讨论(0)
  • 2020-12-22 22:07
    new moment(timeStamp,'yyyyMMddHHmmssfff').toDate()
    
    0 讨论(0)
  • 2020-12-22 22:12

    Moment.js provides Localized formats which can be used.

    Here is an example:

    const moment = require('moment');
    
    const timestamp = 1519482900000;
    const formatted = moment(timestamp).format('L');
    
    console.log(formatted); // "02/24/2018"
    
    0 讨论(0)
  • 2020-12-22 22:15

    This function creates date from timestamp:

        function formatDateTime(dateString) {
            const parsed = moment(new Date(dateString))
    
            if (!parsed.isValid()) {
                return dateString
            }
    
            return parsed.format('MMM D, YYYY, HH:mmA')
        }
    
    0 讨论(0)
提交回复
热议问题