| Author |
Date and Datetime creation from a String.
|
Lucas Franceschi
Ranch Hand
Joined: Nov 10, 2008
Posts: 106
|
|
hello fellows.
I hope you are all in good mood today!
because I need some help from you guys.
thats the problem:
I have (coming from an XML file) this String "2008-06-06 10:23:27.14" and this string: "2008-06-06" right?
so, I need to create Datatime and Data objects from this string.
I tryed to split the string, having 6 Strings, representing year, month, day, hour, minutes, seconds and nanos, and then use the constructor for timestamp using all this parameters.
beside, this constructor got deprecated, and I haven't got correct results (confused date and time).
Same happened with the date string.
So, what do you fellows say?
|
Lucas Franceschi
Software Developer for SGI Sistemas, lukas1596@gmail.com
|
 |
Steve Luke
Bartender
Joined: Jan 28, 2003
Posts: 3026
|
|
The only Timestamp I found that has 6 parameters is the javax.sql.Timestamp, since you aren't using SQL I would guess that isn't the best tool to be using.
In fact, what you have is a Date (as in java.util.Date), and in one case you have Time values and in the other you don't.
My suggestion would be to use java.text.DateFormat to parse the Strings. If the format presented from the XML doesn't fit into one of pre-defined DateFormats, then you may need to use java.text.SimpleDateFormat to create your own format String.
|
Steve
|
 |
Lucas Franceschi
Ranch Hand
Joined: Nov 10, 2008
Posts: 106
|
|
|
well, this class is dealing with database, so i am using java.sql.datetime... any changes?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
You can create any SQL date type from a java.util.Date:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Date and Datetime creation from a String.
|
|
|