5 messages in com.mysql.lists.win32RE: Java syntax for importing dates i...| From | Sent On | Attachments |
|---|---|---|
| Januski, Ken | 24 Jan 2002 19:31 | |
| Aaron West | 25 Jan 2002 09:35 | |
| Januski, Ken | 25 Jan 2002 13:10 | |
| webm...@w3space.com | 25 Jan 2002 17:10 | |
| Januski, Ken | 28 Jan 2002 14:22 |
| Subject: | RE: Java syntax for importing dates into mySql![]() |
|---|---|
| From: | Januski, Ken (kjan...@phillynews.com) |
| Date: | 01/28/2002 02:22:23 PM |
| List: | com.mysql.lists.win32 |
Thanks Thomas,
For the moment I'm getting by with using NOW(). But I had been fooling around with code such as this: public static String getDate() { Calendar rightNow = Calendar.getInstance(); String myDate = rightNow.get(Calendar.YEAR) + "-" + (rightNow.get(Calendar.MONTH)+1) + "-" + rightNow.get(Calendar.DAY_OF_MONTH); return myDate; }
This is I'm sure pretty unsophisticated Java but I'm pretty new to it. If you have any more detailed suggestions for setting up dates to work with mySQL I'd be happy to hear them.
Ken
-----Original Message----- From: Downing, Thomas [mailto:Thom...@ipc.com] Sent: Monday, January 28, 2002 1:35 PM To: Januski, Ken Subject: RE: Java syntax for importing dates into mySql
See java.text.DateFormat. Look in the MySql docs for the correct date format, and build a DateFormat object that will produce that format.
As an aside to newer java Developers - a DateFormat object is rather expensive to construct. If you plan on using a given date format often, construct a static DateFormat with the desired format, then reuse it with a java.util.Calendar object. The Calendar object contains the current date/time in your locale, the DateFormat formats it for output (such as a string in a MySql query.)
If you want more details, email here or direct to thom...@ipc.com
td
-----Original Message----- From: Januski, Ken [mailto:kjan...@phillynews.com] Sent: Thursday, January 24, 2002 10:32 PM To: win...@lists.mysql.com Subject: Java syntax for importing dates into mySql
Hi,
I'm fairly new to Java and am trying to find the best method to format a current date to import into a date field in mySQL. I've done it in Perl but now am working in Java. I'm sure this is a common problem so am wondering if anyone has any ideas. I've been searching the mailing list archives but have found nothing so far.
Thanks,
Ken Januski
--------------------------------------------------------------------- Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before posting. To request this thread, e-mail win3...@lists.mysql.com
To unsubscribe, send a message to the address shown in the List-Unsubscribe header of this message. If you cannot see it, e-mail win3...@lists.mysql.com instead.




