I want to parse date of following type:
2010-07-13T17:27:00.000Z
How can i do it using simple date formatter in java? what format is to be used?
I want to parse date of following type:
2010-07-13T17:27:00.000Z
How can i do it using simple date formatter in java? what format is to be used?
(You may notice that I'm not actually giving you the format string. This is a "teach a man to fish" answer. If you have problems working out specifically what you'd need to use for a particular section, then feel free to elaborate, stating what you tried and why it didn't work. But right now it sounds like you haven't got to the point of attempting any specific format strings. The Javadocs are reasonably well-written and contain everything you need. Being able to extract information from documentation is a massively important skill for a programmer and I'm not going to rob you of a chance to improve on it.)
The code should look like the following code.
For your date string "2010-07-13T17:27:00.000Z
" you may try this format "yyyy-MM-dd'T'hh:mm:ss.S'Z'
".
I assume the 'T' and 'Z' in your date string is constant/separator only.
import java.text.SimpleDateFormat;
import java.util.Date;
public class TestMain {
public static void main(String[] args) throws Exception{
String fromDateTime = "2010-12-01 00:01:23";
DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date date = null;
date = format.parse(fromDateTime);
//What ever you want to manipulate of this date object
//...
}
}
EDIT: add proper class, method & comment to make it a complete program. Thanks for comment from @Andrzej Doyle. EDIT: remove throws IOException from the demo program. Thanks for @BalusC. EDIT: re-read the comment, got the full meaning of @BalusC :)