• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

change data type from string to timestamp

 
elli dian
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanto to change data type from string to timestamp,
but I get a not suitable value according format DD-MM-YYYY

My coding :
String fdate="02-05-2006";
SimpleDateFormat dateFormat = new SimpleDateFormat("DD-MM-yyyy");
java.util.Date parsedFDate = dateFormat.parse(fdate);
java.sql.Timestamp fdateabsence=new java.sql.Timestamp(parsedFDate.getTime());

I get result=2006-01-02 00:06:00.0

Please help me... so I get result according my fdate is=02-05-006 and data type will be timestamp
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[/b]
[ June 08, 2006: Message edited by: Ankur Sharma ]
 
elli dian
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get still a false value: if I use format dd-MM-yyyy
the result is:2006-05-02, but I want to get a value:02-05-2006.
Please help me again?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you don't understand the difference between a Timestamp object and the string representation of a Timestamp object.

A Timestamp object contains a date and time. It does not have a specific format by itself. If you call toString() on a Timestamp, you might get a String that looks like "2006-01-02 00:06:00.0". The toString() method uses a default format, because it has to convert the date and time value into a String somehow. But again, the format itself is not a property of the Timestamp object.

If you want to convert the Timestamp object to a String with a specific format, you need to use the SimpleDateFormat.format(...) method, which allows you to specify a specific format.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic