Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

Re: get day of week for the selected date

but if my date is String str = "10/03/2004"

the it will show me 10 in console

 

Calendar rightNow = Calendar.getInstance();
rightNow.set(Calendar.YEAR, 2004);
rightNow.set(Calendar.MONTH, 03);
rightNow.set(Calendar.DAY_OF_MONTH, 10);

System.out.println("----DAY_OF_WEEK-------"+rightNow.get(Calendar.DAY_OF_MONTH ));

Developer
simon_hain
Posts: 16,354
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: get day of week for the selected date

there is a connection between the text and the meaning.
Calendar.DAY_OF_MONTH <- day of month
Calendar.DAY_OF_WEEK <- day of week

if you set the day of month to 10 and print the day of month you get 10, should not be too surprising.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

Re: get day of week for the selected date

i think we have a confusion let me clear it,

 i have String str = "10/03/2004" and in this string
10 is date
03 is month and
2004 is year  

and i want to find the day like wheather it is Sunday, monday .. and so on..?

Developer
simon_hain
Posts: 16,354
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: get day of week for the selected date

you already got the result, it was 2. I checked an online service, and the date you gave is a tuesday.
2 is the value of Calendar.TUESDAY, if you want to get a string like "Tuesday" you would have to map this yourself, for example in a switch/case statement.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

Re: get day of week for the selected date

and in the code where should i put the date 

String str = "10/03/2004"

 

10 is date
03 is month and
2004 is year  

 

Calendar rightNow2 = Calendar.getInstance();
rightNow2.set(Calendar.YEAR, 2004);
rightNow2.set(Calendar.MONTH, 03);
rightNow2.set(Calendar.DAY_OF_MONTH, 10);

System.out.println("----DAY_OF_WEEK-------"+rightNow2.get(Calendar.DAY_OF_MONTH ));

Developer
simon_hain
Posts: 16,354
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: get day of week for the selected date

first, replace
System.out.println("----DAY_OF_WEEK-------"+rightNow2.get(Calendar.DAY_OF_MONTH ));
with
System.out.println("----DAY_OF_WEEK-------"+rightNow2.get(Calendar.DAY_OF_WEEK ));
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

Re: get day of week for the selected date

i use your code and that shows me 6 in console , what does it mean?
Developer
simon_hain
Posts: 16,354
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: get day of week for the selected date

6 would be Calendar.SATURDAY i think. Which would translate to Saturday.
Which would be the 6th day in the week, at least when you start counting on Monday.

The day of week is numbered from 1 to 7, and the day of month from 1 to 31.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900

Re: get day of week for the selected date

ok fine but when i change the date to String input_date="20/05/2013" and on this date it is monday,

and it shows me 5 in console, and 5 stands for Friday

 

Calendar rightNow2 = Calendar.getInstance();
rightNow2.set(Calendar.YEAR, 2013);
rightNow2.set(Calendar.MONTH, 05);
rightNow2.set(Calendar.DAY_OF_MONTH, 20);
System.out.println("----DAY_OF_WEEK-------"+rightNow2.get(Calendar.DAY_OF_WEEK ));

Developer
peter_strange
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: get day of week for the selected date

rightNow2.set(Calendar.MONTH, 05);

 

Month 5 is June.  January is Month 0. 

 

Review the API for the constant value

Calendar.JANUARY.