Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

trouble with date

 
kevin schmidt
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm displaying information from a directory where things are dated. The program allows the user to view files from previous weeks. What I want to do is be able to display at the top of the page "News from the week of 'Monday, July 20th, 2001'", where 'Monday, July 20th, 2001' is genereated by the code. The problem is I'm not sure how to get the date so it always displays the Monday of the week, the start of the work week. I hope this is clear!! TIA.
Kevin
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I get it?

You are filtering the contents of a directory to show 'a week at a time'?

If you know that you want to show all files between 'day x plus 7 days' where day x is always a Monday...

Then maybe you could use a GregorianCalendar object. This is a pretty big and complicated class (or so I found), but also pretty powerful.

You can initially set it's value to BE a Monday. Henceforth, you can simply add whole weeks at a time to it, and if you add whole weeks, then the calendar's current day will always be Monday.

Am I close?
[This message has been edited by Mike Curwen (edited September 19, 2001).]
 
Tom Ben
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this will help you or not. Hope it does.
import java.util.GregorianCalendar;
import java.util.Calendar;
public class Dates {
public static void main (String args[]) {
GregorianCalendar cldr = new GregorianCalendar();
int year = cldr.get(Calendar.YEAR);
int day = cldr.get(Calendar.DAY_OF_MONTH);
//String dow = dayOfWeek(cldr.get(Calendar.DAY_OF_WEEK));
//String moy = monthOfYear(cldr.get(Calendar.MONTH));
String date = dayOfWeek(cldr.get(Calendar.DAY_OF_WEEK))+", "+monthOfYear(cldr.get(Calendar.MONTH))+" "+day+", "+year;
//System.out.println(dow+", " + moy+" "+day+", "+year);
System.out.println(date);
}
public static String monthOfYear(int dayw) {
String monofyear = "";
switch (dayw) {
case 0:
monofyear = "January";
break;
case 1:
monofyear = "February";
break;
case 2:
monofyear = "March";
break;
case 3:
monofyear = "April";
break;
case 4:
monofyear = "May";
break;
case 5:
monofyear = "June";
break;
case 6:
monofyear = "July";
break;
case 7:
monofyear = "August";
break;
case 8:
monofyear = "September";
break;
case 9:
monofyear = "October";
break;
case 10:
monofyear = "November";
break;
case 11:
monofyear = "December";
break;
}
return monofyear;
}
public static String dayOfWeek(int dayw) {
String dayofweek = "";
switch (dayw) {
case 1:
dayofweek = "Sunday";
break;
case 2:
dayofweek = "Monday";
break;
case 3:
dayofweek = "Tuesday";
break;
case 4:
dayofweek = "Wednesday";
break;
case 5:
dayofweek = "Thursday";
break;
case 6:
dayofweek = "Friday";
break;
case 7:
dayofweek = "Sunday";
break;
}
return dayofweek;
}
}

------------------
Sun Certified Programmer on the Java 2 Platform
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic