posted 11 years ago
Hi all
I am reading in two fields from a database, both are strings. The first string is in the format yyyymmdd(year month day) ex 20060801. The second is hhmmss(hours minutes seconds) ex. 231127. I have an object that takes a Timestamp as an argumnet to its constructor. I need to somehow manipulate these two strings into a time stamp so I can pass them to the other object. I looked at Timestamp and it looks like the deprecated way is to flat out parse both strings into the individual parts and pass them into the Timestamps constructor. I saw the new way is to pass the mili seconds into the Timestamps constructor. Any thoughts on how I can do this?
Thanks,
AMD

I am reading in two fields from a database, both are strings. The first string is in the format yyyymmdd(year month day) ex 20060801. The second is hhmmss(hours minutes seconds) ex. 231127. I have an object that takes a Timestamp as an argumnet to its constructor. I need to somehow manipulate these two strings into a time stamp so I can pass them to the other object. I looked at Timestamp and it looks like the deprecated way is to flat out parse both strings into the individual parts and pass them into the Timestamps constructor. I saw the new way is to pass the mili seconds into the Timestamps constructor. Any thoughts on how I can do this?
Thanks,
AMD
posted 11 years ago
If you just store yyyymmdd why do you need timestamp? Why Date objects aren't sufficient. Anyway the answer to your question is you need to parse the String value into date object using SimpleDateFormat and then get the long value of the date object and pass it as arg to Timestamp constructor.
Andrew Mcmurray
Ranch Hand
Posts: 188

It is sorta covered in the JavaRanch Style Guide. |