473,395 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

String to Date JAVA

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
2 1935
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
in java, you can use the class SimpleDateFormat which can help us to format String to Date.
Jun 2 '12 #3

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

Similar topics

9
by: Hebar Tiltwobler | last post by:
I need to figure out if the current date (passed in as a string) is equal to or greater then a field in my database in the format of- M/D/YYYY AND if the date is less then another field in my...
2
by: Dan | last post by:
Hello. I have recently tried upgrading the MySql connector for my servlet from 2.0.4 to 3.0.9. I have found a minor limitation in 2.0.4 and was hoping that 3.0.9 would fix it. However, now I...
1
by: ree32 | last post by:
I am having problems with Date Strings when using VS.net method of converting an XML document to a dataset. I need the the date nodes to be of date type. As I am loading the Dataset to a...
5
by: David Requena | last post by:
Hi All, I'm trying to parse a file which has some timestamps embedded. These're expressed as a number of seconds elapsed since 01/01/1904 (macintosh time). I know OS X provides some APIs to...
2
by: safaritn | last post by:
High all, I want to calculate the difference between two date with DiffTime function which use time_t structure of the two date. But the two date are in string format. So, how can I do to convert...
14
by: prasath03 | last post by:
Dear All, I have one doubt for how to insert the java.sql.Date into ms-sql server. I tried the below code but it couldn't be inserted. I did wrong in my code that is ps.setDate(1,full_date_time)...
2
by: Chris H | last post by:
Hi, I'm trying to concatenate a Description (nchar(100)) and Date (datetime) as Description and my initial effort was just "...description+' '+open_date as description..." which throws a date/...
9
by: Apollo1376 | last post by:
Hi, I have a vector<string> Date, which contains all the dates. I will be given a starting date and the ending date. I want to compare the 'staring date' with the dates in the Date vector. I am...
19
by: robtyketto | last post by:
Greetings, I have the following code below which allows the date to be added via a JDBC connection as a STRING. The value of dateString is inserted into the MS ACCESS database. What is the...
1
by: eldadno1 | last post by:
I'm actually a Java programmer, and I'm messing with JNI a bit, so I've managed to pass an int from java to c++ and to c# and back. no problems cause it gets serialized automatically. but when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.