aspose file tools*
The moose likes Beginning Java and the fly likes Get the day Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Get the day" Watch "Get the day" New topic
Author

Get the day

Munaathejavaboy Munna
Greenhorn

Joined: Jun 26, 2003
Posts: 1
hello hi i have made a program that is A date validation programe like if u enter this date 29 2 1981 this is an invalid date so my program is Sucessful but i want it to upgrade it like if the user enters a date it also displays the Day name like Tuesday , friday sumthing like that i have done every thing like to display owt the month is But i have a problem displaying the day please help me out with the Day name printing programe I m still a bigiiner


Thank U
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Are you putting your date into a Date or Calendar object of some type? Look at GegorianCalendar.get(Calendar.DAY_OF_WEEK) to get an int. Could you use that int as an array index to get the name of the day? Lemme know if that helped.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Munaathejavaboy Munna,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
philip brocklesby
Greenhorn

Joined: Jun 15, 2003
Posts: 1
Hi Munna,
Heres a programme I did about a month ago... based on Zellers congruence...
if you are using day1, month1, year1, day2, month2 year2 you need to parse int these so you can input the dates for the years and the Zellers congruence will return the day for the the dates you entered...
eg:

int day1=Integer.parseInt(args[0]);
int month1=Integer.parseInt(args[1]);
int year1=Integer.parseInt(args[2]);
int day2=Integer.parseInt(args[3]);
int month2=Integer.parseInt(args[4]);
int year2=Integer.parseInt(args[5]);

public static String dateName( int day, int month, int Year ){
int D = day;
int M = month-2;
if(M<=0){
M=M+12;
}
String Days[] = {" Sunday", "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
String myYear =Integer.toString(Year);

String CENT=myYear.substring (0,2);
String YR=myYear.substring (2);


int C = Integer.parseInt(CENT);
int Y = Integer.parseInt(YR);

int d1=(int)Math.floor((2.6*M)-02);
int num = d1+D+Y;
int d2 = (int)Math.floor(Y/4);
num = d2 + num;
int d3 = (int)Math.floor(C/4);
num = d3 + num;
num = num - (2*C);
int di = num%7;
String d = Days[di];
return d ;
}
I hope you find this of some use
bye for now
Philby
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
This seems to work OK - you will need to get your valid date into a date object, something like the following (output is: Friday, 29 02 1980)
 
 
subject: Get the day