Ive done a bit of VB.NET work before, and doing java for computer science at uni. What im trying to do is convert a string formated "DD/MM/YYYY HH:MM" to a string formated like "'WEDNESDAY, 14TH APRIL 2006" .
The class Timestamp is used to represent a time in place. Initlizing it with the time/date. Then being able to use the method .toString() to get the date in full.
I dont think im parsing the date as a string properly, and when i run it as is, it doesnt throw an exception. However if i run it with myDateTimeGroup.toString() as the return value, it throws exception null. Hence why i dont think the date (as string) is being parsed properly. Any ideas?
Code:
/ CONSTRUCTOR - STRING MUST BE 'DD/MM/YYYY HH:MM'
public Timestamp(String datetime) {
// SPLIT DATETIME INTO VARIABLES AND SET THEM [working]
myDate = Integer.parseInt(datetime.substring(0, 2));
myMonth = Integer.parseInt(datetime.substring(3, 5));
myYear = Integer.parseInt(datetime.substring(8, 10));
myHour = Integer.parseInt(datetime.substring(11, 13));
myMinute = Integer.parseInt(datetime.substring(14, 16));
}
// RETURNS STRING FORMATED LIKE - 'WEDNESDAY, 14TH APRIL 2006'
public String toString() {
DateFormat df = DateFormat.getDateInstance(DateFormat.FULL);
ParsePosition pos;
try {
pos = new ParsePosition(0);
myDateTimeGroup = df.parse(String.valueOf(myDate) + "/"
+ String.valueOf(myMonth) + "/" + String.valueOf(myYear),
pos);
return " ";
} catch (Exception e) {
return "ERROR - " + e.getMessage();
}
}