By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,654 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,654 IT Pros & Developers. It's quick & easy.

String to Date JAVA

P: 1
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
May 22 '12 #1
Share this Question
Share on Google+
2 Replies


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

Expand|Select|Wrap|Line Numbers
  1.         public string changeToDate(string input)
  2.         {
  3.             string day = "";
  4.             string month = "";
  5.             string year = "";
  6.  
  7.             for (int i = 0; i < 4; i++)
  8.                 year += input[i];
  9.             month = input[5].ToString() + input[6].ToString() + "/";
  10.             day = input[8].ToString() + input[9].ToString() + "/";
  11.  
  12.             return (month + day + year);
  13.         }
May 23 '12 #2

P: 4
in java, you can use the class SimpleDateFormat which can help us to format String to Date.
Jun 2 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.