I want to get the Date in MM/DD/YY
format from a timestamp.
I have used the below method but it does not gives proper output
final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(Long.parseLong(1306249409)); Log.d("Date--",""+cal.DAY_OF_MONTH); Log.d("Month--",""+cal.MONTH); Log.d("Year--",""+cal.YEAR);
But its gives the output like below
Date--5 Month--2 Year--1
The correct date is 24 May 2010 for Timestamp - 1306249409
Note - Timestamp is received by a webservice which is used in my application.
The dates appear as, mm/dd/yyyy in the U.S. and as, dd/mm/yyyy outside the U.S. where mm is the month, dd is the day, and yyyy is the year. The time is displayed as, hh:mm:ss AM/PM, where hh is the hour, mm is minutes, and ss is seconds.
To calculate UTC time one has to subtract the offset from the local time, e.g. for "15:00−03:30" do 15:00 − (−03:30) to get 18:30 UTC. Show activity on this post. That timestamp has a timezone offset that is telling you what time it was and the UTC offset.
The T doesn't really stand for anything. It is just the separator that the ISO 8601 combined date-time format requires. You can read it as an abbreviation for Time. The Z stands for the Zero timezone, as it is offset by 0 from the Coordinated Universal Time (UTC).
Better Approach
Simply Use SimpleDateFormat
new SimpleDateFormat("MM/dd/yyyy").format(new Date(timeStampMillisInLong));
Mistake in your Approach
DAY_OF_MONTH
,MONTH
, .. etc are just constant int value used by Calendar
class internally
You can get the date represented by cal
by cal.get(Calendar.DATE)
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