Earlier I posted the following question: How can I convert this date in Java?
But now I would like to know how I can convert this string into a date/time.
2010-03-15T16:34:46Z
For example: 03/15/10
UPDATED:
String pattern = "MM/dd/yy 'at' HH:mm";
Date date = new Date();
try {
date = new SimpleDateFormat(pattern).parse(q.getUpdated_at());
} catch (ParseException e) {
e.printStackTrace();
}
dateText.setText(new SimpleDateFormat("MM/dd/yy 'at' hh:mma").format(date));
Gives me a result like:
Mon Mar 15 16:34:50 MST 2010
How can I format it to be
03/15/10 at 4:34PM
?
In a nutshell, you want to convert a date in a string format to a date in another string format. You have:
and you want
You don’t want to end up using
java.util.Dateobject as you initially implied in your question. You also don’t want to use itstoString()since that returns a fixed format as definied in its javadoc.The answer of Bozho still applies. Use
java.text.SimpleDateFormat. First, you need to parse the date in string format into aDateobject so that you can format it back into another string format.