In this code
long timestamp=1332782463298;
Date d=new Date(timestamp);
date=d.toLocaleString();
date is always current date. Where is my mistake?
I’ve also tried SimpleDateFormat, but it still returns current date:
date=new SimpleDateFormat("MM.dd.yyyy").format(d);
That timestamp is for March 26th 2012 (17:21:03.298 UTC, to be precise). Try a suitably different timestamp (e.g. 1332482563298L) and you’ll get a different date…
Note that you shouldn’t really be using
toLocaleStringanyway –SimpleDateFormatis the way to go (or Joda Time if possible). You might also want to consider which time zone you’re interested in.