I am implementing one android application in which I want to convert timestamp to date but I could not get success. I have tried below things. Please check it if I am doing something wrong.
I am passing this value :
myTimestamp=1328015914;
DateFormat.getDateFormat(mContext).format(new Date(myTimestamp * 1000));
It returns 11/1/1970
but its wrong.
Please help me for this query.
Thanks Manthan Dalal
You might need to specify the time zone. This is the method i use.
private String getDate(long timeStamp){
DateFormat objFormatter = new SimpleDateFormat("dd-MM-yyyy");
objFormatter.setTimeZone(TimeZone.getTimeZone(timezone));
Calendar objCalendar =
Calendar.getInstance(TimeZone.getTimeZone(timezone));
objCalendar.setTimeInMillis(timeStamp*1000);//edit
String result = objFormatter.format(objCalendar.getTime());
objCalendar.clear();
return result;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With