Reputation: 4670
i m doing json parsing and i getting response for data like
"date":"1330387200"
so i can convert this response into date format like "DD/MM/YYYY"?. Does any body have idea please send me.
Thanx in advance.
Upvotes: 1
Views: 1273
Reputation: 143
Date d = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM d, yyyy");
for (int i = 0; i < vTitle.size(); i++)
{
String dt = date.elementAt(i).toString().substring(0, 10);
Date formatter = new Date(HttpDateParser.parse(dt));
String strCustomDateTime = dateFormat.format(formatter);
Upvotes: 1
Reputation: 3726
This is one line code:
public String getDate(long value)//1330387200
{
return new SimpleDateFormat("dd/mm/yyyy").formatLocal(value);
}
Test this one;
Upvotes: 1
Reputation: 4670
i have solve this issue using this code.
private String getDate(long dat)
{
SimpleDateFormat sdf=new SimpleDateFormat("dd/MMM/yyyy");
Date dt=new Date(dat*1000);
String dtInFormat=sdf.format(dt);
return dtInFormat;
}
Upvotes: 2
Reputation: 18064
Try this way:-
var myObj = $.parseJSON('{"date":"1330387200"}'),
myDate = new Date(1000*myObj.date);
alert(myDate.toString());
alert(myDate.toUTCString());
Upvotes: 0
Reputation: 29199
Create a SimpleDateFormat
SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/YYYY");
parse your date string to long:
long time=Long.parseLong(timeStamp);
Date dt=new Date(time);
String dtInFormat=sdf.format(dt);
Resultant string dtInFormat would be in desired format.
Upvotes: 2