Originally posted by sony rao:
hi Henrique
i tried what Jesper said..
Date now = new Date();
System.out.println("date--> " + now);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
String s = df.format(now);
String result = s.substring(0, 26) + ":" + s.substring(27);
System.out.println("result--> " + result);
output:
date--> Fri Mar 14 10:27:31 IST 2008
result--> 2008-03-14T10:27:31.197+05:0
"2008-03-14T10:27:31.197+05:0" is not the format i want my result to be.
it should be in MM/dd/yyyy hh:mm a format
So I made a little mistake. It should have been:
String result = s.substring(0, 26) + ":" + s.substring(26); But what do you really want? First you said you wanted a format like 2008-03-14T10:27:31.197+05:00 and now you're talking about MM/dd/yyyy hh:mm.
Do you mean you want to
parse a date in a format like 2008-03-14T10:27:31.197+05:00, and then
format it into MM/dd/yyyy hh:mm? You can do that like this:
1. Manually remove the ":" from the input string using substring().
2. Use a SimpleDateFormat object with the format "yyyy-MM-dd'T'HH:mm:ss.SSSZ" and call parse() on it to parse the input string into a Date object.
3. Use another SimpleDateFormat object with the format "MM/dd/yyyy hh:mm" and call format() on it to format the Date object into the output string.
[ March 14, 2008: Message edited by: Jesper Young ]