Convert unix timestamp to normal Date in Json

7k views Asked by At

I am using laravel 5.0. I am getting data from controller as json. I am having value like this.

{"timstamp_date":"1434360957"},

I need to convert this unix timestamp value as Normal Date Like (15-06-2015) or (15-March-2015).

I have used Date(timstamp_date) but it is showing current time only. Not my timstamp date

2

There are 2 answers

4
teoreda On BEST ANSWER

You could use:

date("d-m-Y H:i:s", 1434360957);

EDIT You could try;

var dateTime = new Date(1434360957*1000);
var formatted = dateTime.toGMTString();

https://jsfiddle.net/sp57Lnpf/

3
haakym On

Use the date function. You need to specify the format as the first parameter:

date("d-m-Y", $timestamp_date)

http://php.net/manual/en/function.date.php

Laravel also comes with Carbon you could use that if you wanted to for further manipulation of the data if you so required it.

http://carbon.nesbot.com/docs/