Don Hill
Posts: 70
Nickname: ssswdon
Registered: Jul, 2002
|
|
Re: Timestamp format to yyyyMMdd using simple date format
|
Posted: Oct 8, 2002 8:17 AM
|
|
first off sdf.parse only creates a Date() from a string and if you don't call format() you won't get the formated date back, it appears to me that the ************2002-09-19 11:47:15.956000 is your value that you are parsing and > ************Sun Dec 09 00:00:00 GMT+05:30 2001 is the default .toString() for a Date and > ********* 20011210 is the correct format according to SimpleDateFormat("yyyyMMdd");
So the question is what really do you want to happen ? If you want this format then here is how to do it. ---------------------- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); // learn to use the interface java.util.Calendar gCal = new= new GregorianCalendar();
String strDate = this.find("LastInterestAccrual Date").getValue();
Date newDate = sdf.parse( strDate);
String formatDate = sdf.format( newDate );
HTH
> Hi All, > > I m passing an string with date in timpestamp > format,changing its format to yyyyMMdd,and adding > one day in it,but my prob is that simple date format > ,parses a different date value from timestamp > string...here is the code > <code> > SimpleDateFormat sdf = new > SimpleDateFormat("yyyyMMdd"); > > java.util.GregorianCalendar gCal = new > l = new GregorianCalendar(); > > > > > > > > gCal.setTime(sdf.parse(this.find("LastInterestAccrual > ate").getValue())); > System.out.println("************" + > ****" + > this.find("LastInterestAccrualDate").getValue()); > System.out.println("************" + > ****" + > sdf.parse(this.find("LastInterestAccrualDate").getValu > ())); > > java.util.Date newDate = new > e = new java.util.Date(gCal.getTime().getTime() + > 1000 * 60 * 60 * 24); > > sdf = new SimpleDateFormat("yyyyMMdd"); > System.out.println("********* " + > *** " + sdf.format(newDate)); > > return sdf.format(newDate); > </code> > > > here is the output of above three println stmnts. > ************2002-09-19 11:47:15.956000 > ************Sun Dec 09 00:00:00 GMT+05:30 2001 > ********* 20011210 > > so , in first line , the correct timestamp is being > printed,but somehow , in second line,simpe date > formats parse it to totally differnt value,and then > add 1 day into it. > > Any Idea? > > thanks > Rohit
|
|