cancel
Showing results for 
Search instead for 
Did you mean: 

Error in SimpleDateFormat Implementation?

achim_hauck2
Active Contributor
0 Kudos

hi,

I'm trying to convert a String like "YYYYMMDD" in a Date-object.

Obviously that would be a perfect task for the SimpleDateFormat, but something gets wrong:

Example:


SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
String datString= "20040131";
Date parsedDate = df.parse(datString);
System.out.println(parsedDate.getDay());
System.out.println(parsedDate.getMonth());
System.out.println(parsedDate.getYear());

results in:

6, 0, 104....

ok, Date.getXXX is deprecated, but I'v also tried


Calendar cal = Calendar.getInstance();
cal.set(parsedDate);
System.out.println(cal.get(Calendar.<FIELD>));

the same wrong dates...

any ideas?

kr, achim

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

the SimpleDateFormat works fine.

You could check that by adding the line

System.out.println(parsedDate);

to your code.

getDay() returns the day of the week: 31st Jan 2004 is a Saturday, so depending on your settings the 6th day of the week.

getMonth() counts from 0 to 11. So the first month is 0.

getYear() Returns a value that is the result of subtracting 1900 from the year that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

Details on these methods (which are all deprecated) could be found in the SDK api.

I hope that answer could help. If not, please specify the purpose of using those methods. Perhaps we could find better alternatives.

Best Regards, Astrid

achim_hauck2
Active Contributor
0 Kudos

thanks,

actually i use the Calendar-getters/setters, the (deprecated) Date.getXXX-methods i used only for debugging purposes but not realizing in which values they result...

bad luck.

now everything works fine (i believe it did before, too.)

the usage of this conversation is to use the Date-values of a WebDynpro-UI-Date-Element in a String of format "yyyymmdd" and vice versa.

Is there a ready-to-use funtion already in NDS / WebDynpro?

kr, achim

Answers (0)