我希望将我的日期格式更改为 MM/DD/YYYY,目前它在 YYYY/MM/DD 中。
我尝试研究它,但具有讽刺意味的是,它总是相反。现在有人可能会说向后尝试尝试从那里开始工作,但它没有用。
我的类调用所有的东西:
import java.util.*;
import java.text.*;
class Driver {
public static void main (String[] args) {
Kid kid;
Node list = new Node();
kid = createKid("Lexie", 2.6, "11/5/2009");
insertEnd(list, kid);
kid = createKid ("Sally", 2.3, "4/8/2009");
insertEnd(list, kid);
kid = createKid ("Joe", 2.7, "6/16/2009");
insertEnd(list, kid);
kid = createKid ("Bob", 2.2, "1/16/2009");
insertEnd(list, kid);
kid = createKid ("Tom", 3.1, "8/16/2009");
insertEnd(list, kid);
printList(list);
} //end main method
public static Kid createKid(String name, double height, String date) {
return new Kid(name, height, date);
}
} //end class
import java.util.*;
import java.text.SimpleDateFormat;
import java.io.*;
class Kid {
String name;
double height;
GregorianCalendar bDay;
...
/**
* Second constructor for kid
* Setting instances to equal the constructors of this
* @param 1: Setting n (aka name, but it was taken) to equal the instance var of name
* @param 2: Setting h (aka height, but it was taken) to equal the instance var of height
* @param 3: Setting date to equal the instance var of bDay with some modifications
*/
public Kid (String n, double h, String date) {
StringTokenizer st = new StringTokenizer(date, "/");
this.name = n;
this.height = h;
this.bDay = new GregorianCalendar(Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
}
/**
* public String toString() {
* Converting Java language to English language
*/
public String toString() {
return (this.name + ", Height: " + this.height + "ft., Born: "
+ this.bDay.get(Calendar.DATE) + "/" + this.bDay.get(Calendar.MONTH)
+ "/" + this.bDay.get(Calendar.YEAR));
}
} //end class
顺便说一句,我不熟悉的简单日期格式类和日期格式类,并没有成功地尝试实现它们。