Jeetandra,
You need to check out the SimpleDateFormat class. It can format a date
exactly as you need to have it. If you want to see some example code,
check out our Date/Time servlet on http://www.coolservlets.com. Below
might also be enough:
import java.util.Date;
import java.text.SimpleDateFormat;
SimpleDateFormat simpleDate = new SimpleDateFormat();
simpleDate.applyPattern("yyyyMMdd");
out.println(simpleDate.format(new Date()));
I'm pretty sure that might even be the exact pattern that you're looking
for.
Good luck!
-Matt Tucker
Jeetandra Mahtani wrote:
>
> Hello,
> I have a hidden Date field in a form. Before the
> servlet can add a record to the database, I need to
> set this date field to the current date but I can't
> seem to get the year in the format of yyyy. Also, I
> need the Date and the month to always be of two
> characters. Like today it is set as 99526 but I need
> it as 19990526.
> I've been using
> Date c1crdt = new Date();
> String curdate =
> c1crdt.getYear()+c1crdt.getMonth()+c1crdt.getYear();
> Any suggestions/ideas?
> Thanks,
> J
>
> _________________________________________________________
> DO YOU YAHOO!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
--
-------------------------------
Matt Tucker
[EMAIL PROTECTED]
http://cs.uiowa.edu/~matucker
See CoolServlets:
http://www.coolservlets.com
-------------------------------
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html