String to Date JAVA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tantan
    New Member
    • May 2012
    • 1

    String to Date JAVA

    i have a string of "2012-10-21 00:00:00"
    and i have to set change its format to MM/dd/yyyy
    thanks in advance
  • firexfighterx
    New Member
    • May 2012
    • 14

    #2
    I have a very straight forward solution to this. Its a start but it will do the trick. Modify how you wish

    Code:
            public string changeToDate(string input)
            {
                string day = "";
                string month = "";
                string year = "";
    
                for (int i = 0; i < 4; i++)
                    year += input[i];
                month = input[5].ToString() + input[6].ToString() + "/";
                day = input[8].ToString() + input[9].ToString() + "/";
    
                return (month + day + year);
            }

    Comment

    • keep1to2
      New Member
      • May 2012
      • 4

      #3
      in java, you can use the class SimpleDateForma t which can help us to format String to Date.

      Comment

      Working...