A little off topic and easily found in the API, but try this...
java.sql.Date sDate1 = null;
java.text.SimpleDateFormat dFmt = null;
sDate1 = new java.sql.Date( new java.util.Date().getTime() );
dFmt = new java.text.SimpleDateFormat("d MMM,yyyy");
System.out.println("sDate1: " + dFmt.format(sDate1));
--------------------------
G. Stephen Maxfield
stephenm at bear dot com
-----Original Message-----
From: jamsheer [mailto:[EMAIL PROTECTED]]
Sent: Thursday, November 15, 2001 7:53 AM
To: [EMAIL PROTECTED]
Subject: current time to java.sql.Date
Hi,
Here is my problem..I want to insert the current date to a table of a =
database.How can I get the current date in java.sql.Date?I used the =
following code,but I think it is not a good idea?Can anyone help me to =
find a solution?
The code is....,
public java.sql.Date getDate()
{
GregorianCalendar gc=new GregorianCalendar();
int y=gc.get(Calendar.YEAR);
int m=gc.get(Calendar.MONTH)+1;
int day=gc.get(Calendar.DATE);
String d=""+y+"-"+m+"-"+day;
java.sql.Date date1=java.sql.Date.valueOf(d); /*string =
to date*/
return date1;
}
And I also want to convert java.sql.Date to a String of format '15 =
Nov,2000'
I used the following code,please send me a better way
public String getString(java.sql.Date d2)
{
String mo[]=3D =
{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}=
;
GregorianCalendar gc=new GregorianCalendar();
gc.setTime(d2);
int m=gc.get(Calendar.MONTH);
int year=gc.get(Calendar.YEAR);
int dy=gc.get(Calendar.DATE);
String str=""+dy+" "+mo[m]+","+year;
return str;
}
I'm using access db and there is only field for date&time ,then how can =
I insert current date & time to the table?
Andow can I show the time in HTML page with client's time zone using =
JSP?
Thanx,
Cheers,
Jam.
***********************************************************************
Bear Stearns is not responsible for any recommendation, solicitation,
offer or agreement or any information about any transaction, customer
account or account activity contained in this communication.
***********************************************************************
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets