java dd_更改YYYY / MM / DD-> MM / DD / YYYY java

  • Post author:
  • Post category:java


我希望将日期格式更改为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

顺便说一下,我不熟悉的简单日期格式类和日期格式类,并且尝试实现它们均未成功。



版权声明:本文为weixin_42512483原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。