This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String[] : cut a Date every Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String[] : cut a Date every "/"" Watch "String[] : cut a Date every "/"" New topic
Author

String[] : cut a Date every "/"

Grégoire Berclaz
Greenhorn

Joined: Feb 19, 2003
Posts: 28
Hello,
I am French and we write dates : "dd/MM/yyyy". I like to save dates in a SQL DB and the format is "yyyy/MM/dd". How can I cut a date every "/"? I like to have an array of String...
Tk you very much
Greg
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Probably the simplest way would be to use the split() method of String. For example:

That will print out:

You would need to reverse the array, but since there are always three elements that should be no problem.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Grégoire Berclaz
Greenhorn

Joined: Feb 19, 2003
Posts: 28
It's ok... tks
 
Consider Paul's rocket mass heater.
 
subject: String[] : cut a Date every "/"