No way Hugo !!! You should use the java.util.GregorianCalendar class , as follows: <code> Calendar calendar = new GregorianCalendar(); Date trialTime = new Date(); calendar.setTime(trialTime); System.out.println("YEAR: "+calendar.get(Calendar.YEAR)); ........here your code... </code>
For any reference, please consult http://java.sun.com/j2se/1.3/docs/api/java/util/GregorianCalendar.html and you will find all the methods() that you need. Regards, Ionel Condor. ----- Original Message ----- From: "hugo" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, October 18, 2002 6:23 AM Subject: obtaining date and time in suitable format for MySQL > Hi > > I am javing a jsp file where I would like to get the current date and > time to be inserted in fields of an SQL table. The date should go into > the MySQL date field and hence should be of format yyyy-mm-dd. I tried > to use java.sql.Date, but I couldn't get it to work. If I simply use > > long date = 0; > java.sql.Date sqlDate = new java.sql.Date(date); > int year = sqlDate.getYear(); > > I get back "70". So obviously I have to get the year from the machine's > time, which is a linux box with Redhat 7.3. > > So I tried this: > > long date = 0; > java.sql.Date sqlDate = new java.sql.Date(date); > String thetime = sqlDate(System.currentTimeinMillis()); > out.println ("SQL time is " + thetime); > > But this didn't work either. > > How do you do this? > > In addition, I would like to get the time, but in decimal format i.e. > rather than 11:15 I would like to get 11.25 > > Is there a way of doing this? > > Any help will be greatly appreciated. > > Thanks > > Hugo > -- > Dr Hugo Bouckaert > Systems and Programming Engineer > > GeoInformatics Exploration Australia P/L > 57 Havelock St > West Perth, WA 6005 > PO Box 1675, West Perth 6872 > > Ph: 61 08 9420 7400 > Fax: 61 08 9226 1299 > > www.geoinformex.com > > ------------------------------------------------------------------------ > This email and any attachments may be confidential or legally > privileged. If you received this message in error or are not the > intended recipient, you should destroy the e-mail message and any > attachments or copies, and you are prohibited from retaining, > distributing, disclosing or using any information contained herein. > Please inform us of the erroneous delivery by return e-mail. Thank you > for your cooperation. > > =========================================================================== > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". > Some relevant FAQs on JSP/Servlets can be found at: > > http://archives.java.sun.com/jsp-interest.html > http://java.sun.com/products/jsp/faq.html > http://www.esperanto.org.nz/jsp/jspfaq.jsp > http://www.jguru.com/faq/index.jsp > http://www.jspinsider.com =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com