Formatting java.sql.Timestamp objects
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ramu_pothuganti
Posted On:   Wednesday, July 31, 2002 01:57 AM

I need to convert java.sql.Timestamp object to the format specified by the user. I am using java.text.SimpleDateFormat class to do formatting. The Pattern specified is "yyyy-MM-dd HH:mm:ss.SSS", after doing formatting of the Timestamp object, it is trimming of milli second part. Is this the correct way of formatting Timestamp values? The way formatting done is given below. SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern("yyyy-MM-dd HH:mm:ss.SSS"); sdf.format(java.sql.Timestamp.valueOf("1970-02-04 01:20:30.456")); After doing formatting, the value I am gettting is 1970-02-04 01:20:30.000. Any pointer   More>>

I need to convert java.sql.Timestamp object to
the format specified by the user. I am
using java.text.SimpleDateFormat class to do formatting.
The Pattern specified is "yyyy-MM-dd HH:mm:ss.SSS", after doing formatting of the Timestamp object, it is trimming of
milli second part. Is this the correct way of formatting Timestamp values?


The way formatting done is given below.


SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyy-MM-dd HH:mm:ss.SSS");
sdf.format(java.sql.Timestamp.valueOf("1970-02-04 01:20:30.456"));


After doing formatting, the value I am gettting is
1970-02-04 01:20:30.000.


Any pointers regarding this would be helpful.


thanks & regards,

ramu    <<Less

Re: Formatting java.sql.Timestamp objects

Posted By:   Gautam_Marwaha  
Posted On:   Wednesday, July 31, 2002 07:05 AM

try:


Timestamp timestamp = ....;
SimpleDateFormat sdf = new SimpleDateFormat();
String str = sdf.format(timestamp);

str is the formatted date string in the reqd. pattern.
About | Sitemap | Contact