Changing YYYY/MM/DD -> MM/DD/YYYY java -


i wish change date formatting mm/dd/yyyy, in yyyy/mm/dd.

i tried researching it, irony, other way around. 1 might try backwards try working there, didn't work.

my class calling things:

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 kid      * setting instances equal constructors of      * @param 1: setting n (aka name,   taken) equal instance var of name      * @param 2: setting h (aka height, taken) equal instance var of height      * @param 3: setting date equal instance var of bday 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 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  

by way, simple date format class , date format class unfamiliar , have unsuccessfully tried implement them.

just use simpledateformat convert string date. no need hassle painful calendar api.

string datestring = "2012/06/05"; date date = new simpledateformat("yyyy/mm/dd").parse(datestring); 

use date object throughout code instead. whenever need present date object humans, use simpledateformat:

string datestring = new simpledateformat("mm/dd/yyyy").format(date); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -