This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes Date problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply 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: 56549
    
  14

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Date problem
 
Similar Threads
Retrive Month and Year
Crazy date program
Date help
A question on java.util.Date
request.getParameter retuning null