Function to convert timestamp to human date in javascript

Function to convert timestamp to human date in javascript

Asked on January 2, 2019 in Javascript.
Add Comment


  • 3 Answer(s)

    Here is the procedure,

    The number of whole milliseconds since 1970-01-01T00:00:00Z is 1382086394000 . This value is about the time . By using the Date constructor we can create ECMAScript Date object with the help of the time value.

    var d = new Date(1382086394000);
    

    We should send the output for call the input in string method. This method gives us the human readable form of time known as equivalent system time.

    For example,

    Fri Oct 18 2013 18:53:14 GMT+1000 (EST)
    

    There are lot of built-in formatting options in In ES5, some examples are,

    • toDateString
    • toTimeString
    • toLocaleString

    For more reference about these build in formats and ECMAScript Date object .

    And one important thing is, we have to format the date ourself if we really want to it is works in all types of browsers.

    alert(d.getDate() + '/' + (d.getMonth()+1) + '/' + d.getFullYear());
    
    Answered on January 2, 2019.
    Add Comment

    For chrome users,

    var theDate = new Date(timeStamp_value * 1000);
    dateString = theDate.toGMTString();
    alert(dateString );
    
    Answered on January 2, 2019.
    Add Comment

    Anyone can simply use this one line code for get the solution,

    new Date (timestamp);
    
    Answered on January 2, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.