• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date and Datetime creation from a String.  RSS feed

 
Ranch Hand
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lucas Franceschi
Ranch Hand
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, this class is dealing with database, so i am using java.sql.datetime... any changes?
 
Sheriff
Posts: 21204
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create any SQL date type from a java.util.Date:
 
Can't .... do .... plaid .... So I did this tiny ad instead:
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!