I am getting compilation error when I try the attached code:
mainDate.java:31: <identifier> expected
cal.setTime( date ) ;
^
mainDate.java:31: <identifier> expected
cal.setTime( date ) ;
^
2 errors
Also how to I put the user input (say "December 30, 1998") onto a String variable (say "myStr2")? My above code is not working well (when I run the program, after typing in the code and hitting enter, it does not exit the program until I hit control-C.)
Main Topics
Browse All Topics





by: ksivananthPosted on 2008-02-27 at 05:12:20ID: 20993622
use simple date format to parse the string input to Date... for e.g.,
SimpleDateFormat format = new SimpleDateFormat( "MMMMM dd, yyyy" ) ; //"MM/dd/yyyy" for the other date format
Date date = format.parse( "June 30, 2006" ) ;
Calendar cal = Calendar.getInstance() ;
cal.setTime( date ) ;
int dd = cal.get( Calendar.DATE ) ;
int mm = cal.get( Calendar.MONTH );
int yy = cal.get( Calendar.YEAR ) ;