49

Possible Duplicate:
Converting Timestamp as String to Date in android

My server is returning a timestamp 1322400600 in String, In my android application, i need to convert it like Nov 27, 2011 07:00am. I don't know how to do this please help me out.

- Thanks AvMishra

Solutions:

I used following code to get the desired value

long dv = Long.valueOf(timestamp_in_string)*1000;// its need to be in milisecond
Date df = new java.util.Date(dv);
String vv = new SimpleDateFormat("MM dd, yyyy hh:mma").format(df);
0

2 Answers 2

31

You can use new java.util.Date(Long.parseLong(timeInMillis)). With this Date object there are several ways to extract the date in your desired String format, the simplest way using Date.toString(). Alternatively, and more appropriately you can use a SimpleDateFormat with the exact pattern you want.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks Che Jami! for your quick response.
I used following code to get the desired value long dv = Long.valueOf(timestamp_in_string)*1000;// its need to be in milisecond Date df = new java.util.Date(dv); String vv = new SimpleDateFormat("MM dd, yyyy h:ma").format(df);
6

This should get you the same time format:

System.currentTimeMillis();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.