reset password
Author Message
jiechen
Posts: 3
Posted 13:09 Jan 20, 2013 |

at Create Project page, user enter the "start date" in the format of "mm/dd/yyyy", after reading the SimpleDateFormat API, my understanding is the we should take this field as a text input, and parse it.  im confused about the method and syntax that should be use on 

 

public Date parse(String text,
                  ParsePosition pos)

 

can anyone give an examples on this? thanks!

cysun
Posts: 2935
Posted 19:29 Jan 20, 2013 |

DateFormat dateFormat = new SimpleDateFormat( "MM/dd/yyyy" );
Date date = dateFormat.parse( text );

If you need a Calendar instead of a Date, do

Calendar calendar = Calendar.getInstance();
calendar.setTime( dateFormat.parse( text ) );

And when you read API documentation of a class, don't just read its own methods - read also the methods it inherits.