File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes String to date problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "String to date problem" Watch "String to date problem" New topic
Author

String to date problem

Tim Nachreiner
Greenhorn

Joined: Apr 28, 2011
Posts: 8
I have this class:



I can't figure out how to stuff a date from a JTextfield into this element.



How to I convert date to a date compatible with java.sql.Date?
The larger question is whether passwordChangeDate has the correct data type. Maybe it should have been java.util.Date? I am storing this info in a database. What is the standard way of datatyping date elements that are stored in a database?

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 3144
So you have an object of one class (call it "A") and you need an object of a different class ("B")? Then you need to look at the ways that exist to create a B object, and then see what you might do with your A object to provide the information needed. (This technique is of general use, not just with dates, hence "A" and "B".)

In the simplest case, java.sql.Date would have a constructor that takes a java.util.Date as an arg. It doesn't however (and I have no idea why not--seems like a stupid design choice to me), but it does have another constructor that you can use.

And Welcome to the Ranch!
 
IntelliJ Java IDE
 
subject: String to date problem
 
Threads others viewed
type casting issue
convert a String into Date with SimpleDateFormat
How can I get sysdate in java?
converting dateformat compatible to oracle date
EVIL DATES. Need help
developer file tools