• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Get the day

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
This one time, at bandcamp, I had relations with a tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic