This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date problem" Watch "Date problem" New topic

Date problem

Ikasari Widiyanto

Joined: May 31, 2004
Posts: 29

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

Joined: Jan 10, 2002
Posts: 63548

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

[Asking smart questions] [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
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.


Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Date problem
It's not a secret anymore!