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
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd
Accepted Solution

get day of week for the selected date

i have date and the format for date is 01/04/2004, how can i get the day of week for that date, i mean to say that on that date wheather it's SUNDAY, MONDAY and so on..? plz guide me

Developer
Posts: 16,999
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: get day of week for the selected date

create a calendar object and use get with http://www.blackberry.com/developers/docs/7.1.0api/java/util/Calendar.html#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
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: get day of week for the selected date

i used what you say like Calender.get(Calender.DAY_OF_WEEK);
and that will print 7 in console
what i want is i have date like 01/04/2004 and how should i know that on that date wheather it's SUNDAY, MONDAY and so on..
Developer
Posts: 16,999
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: get day of week for the selected date

read the API, the Calendar class has fields for all days.
7 would be Calendar.SATURDAY
----------------------------------------------------------
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
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: get day of week for the selected date

i triy with this and that show me error on format1.parse(date); The method parse(String) is undefined for the type SimpleDateFormat

 

String input_date="01/08/2012";
SimpleDateFormat format1=new SimpleDateFormat("dd/MM/yyyy");
Date dt1=format1.parse(input_date);
DateFormat format2=new SimpleDateFormat("EEEE");
String finalDay=format2.format(dt1);

Developer
Posts: 16,999
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: get day of week for the selected date

that would be different question, please mark this thread as solved and create a new one with it.
Or better, search for the issue, it has been answered a couple of times already.
SimpleDateFormat is used for output only, you have to parse it yourself.
----------------------------------------------------------
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
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: get day of week for the selected date

this is the same question, i think u did not got my point , as u can see in my post i have String input_date="01/08/2012"; on that date what would be the day of week like SUNDAY,MONDAY and so on..
Developer
Posts: 16,999
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: get day of week for the selected date

no, you said you have a date, and that is usually a "date object".

to parse your string create a calendar and set the day/month/year to the values parsed from your string.
----------------------------------------------------------
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
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: get day of week for the selected date

ok, but i also mentioned in my first post that i have a date like 01/08/2012,
so i have create a calendar ok i understand but i never worked with
how to set the day/month/year to the values parsed from your string.
Developer
Posts: 16,999
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: get day of week for the selected date

http://www.blackberry.com/developers/docs/7.1.0api/java/util/Calendar.html#set(int,%20int)

for example:
set(Calendar.YEAR, 2013)
----------------------------------------------------------
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