The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


I dont think you got it

Posted by Matt Gerrans on November 05, 2001 at 1:29 PM

Why are you doing that silly parseInt() stuff? All the tools you need are built into DateFormat() and Date(). If you have a string in a date, use DateFormat.parse() to get a Date object, which has the necessary methods for getting year, month and day.
If you already have the Date object, as in your example, you can get year, month and day, without a DateFormat, directly from the Date object.

- mfg

> dear deviprasad mundluru

> thanx fer the advise. the jscript works fine!!

> for JAVA however, my fren proposed that i use the SimpleDateFormat. it's kinda sloppy. ehe. but it gets the job done.

> SimpleDateFormat dateFmt =
> new SimpleDateFormat("yyyy-MM-dd");
> TimeZone mst = TimeZone.getTimeZone("CTT");
> dateFmt.setTimeZone(mst);
> String dateString = dateFmt.format(new java.util.Date());
> but to get the exact field of day, month and year.. depends
> on how we define the format.

> year = Integer.parseInt(dateString.substring(2,4))+100;
> month = Integer.parseInt(dateString.substring(5,7))-1;
> day = Integer.parseInt(dateString.substring(8,10));


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us