Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Date problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date problem" Watch "Date problem" New topic
Author

Date problem

Ikasari Widiyanto
Greenhorn

Joined: May 31, 2004
Posts: 29
Hi,

I have a problem getting the day from a string. I hope somebody can help me.
here is my sample code:

String currDate = "";
String month = "";
String year = "";

for(int i=1;i<=31;i++){
currDate = year+"-"+month+"-"+i;
}

I want to display only the date without the month and the year and get the day of that particular date. how to solve this problem? can anybody help me? thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60739
    
  65

Not much to do with JSP, so I'm moving this off to the Java in General (intermediate) forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Hi Ikasari,
I think you can use Gregorian Calendar..



You can refer to GregorianCalendar and Calendar API to get specific purpose you need...

Hope this helps...
Correct me if I am wrong
thanks
daniel
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
The DateFormatter class provides a slick way to do this with only a few lines of code:

(Disclaimer: This code does not come with any warranty, explicit or implied. It has not been compiled or tested, so use at your own risk.)

Consult the API docs for further details.

Layne


Java API Documentation
The Java Tutorial
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Date problem
 
Similar Threads
request.getParameter retuning null
A question on java.util.Date
Date help
Crazy date program
Retrive Month and Year