Win a copy of Machine Learning with TensorFlow this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

change data type from string to timestamp

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1249
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[/b]
[ June 08, 2006: Message edited by: Ankur Sharma ]
 
elli dian
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic