0

I know how to change date to readable format in php like below

$jobpostdate = date("Y-m-d", '1434460015');

how can I do same thing with JavaScript If I have this UNIX timestamp value 1434460015 or any other UNIX timestamp value value like this , I have to do this within ajax success function, what can be the syntax?

Durga
  • 1,283
  • 9
  • 28
  • 54

2 Answers2

1

Simple use

 new Date(1434460015000) //If it's in second convert it into millisecond by *1000 

For format it you need to do it in manual way

    var today=new Date(1434460015000);
     var dd = today.getDate();
        var mm = today.getMonth()+1; //January is 0!
    
        var yyyy = today.getFullYear();
        if(dd<10){
            dd='0'+dd
        } 
        if(mm<10){
            mm='0'+mm
        }
     
    var today = dd+'/'+mm+'/'+yyyy;
alert(today);
squiroid
  • 13,809
  • 6
  • 47
  • 67
0

.toUTCString might be able to help you.

Damian Silva
  • 336
  • 3
  • 19