07-14-2009 08:19 AM
What kind is your String? Do you need something like a DateParser?
Getting a day from date is easy. Use the calendar class:
and set the date with "setTime(Date date)"
and then you can check the day with
int get(int field) and one of the attributes, for days: DAY_OF_WEEK
07-14-2009 08:40 AM - edited 07-14-2009 08:45 AM
Use substring() method of your String instance to get day, month and year separately.
After that use Calendar class instance, for example:
Calendar calendar = Calendar.getInstance();
so, now you can get date from the calendar via:
Date myDate = calendar.getTime();
Please note that months for calendar are counting in different way.
The best way is implement a conversion method that will get a friendly month number: 1..12 and will return one of constants:
Calendar.JANUARY .... Calendar.DECEMBER
07-14-2009 08:43 AM - edited 07-14-2009 08:44 AM
You would have to parse the string yourself.
Should be easy, the delimiter ist "-"
You could have a look at this Java SE code:
It uses not available classes and methods but should give you an idea:
Split up the string with the "-" character, convert to Integer and then set the parts on Calendar instance:
07-14-2009 11:22 AM
As you mentioned -
>> Please note that months for calendar are counting in different way.
>> The best way is implement a conversion method that will get a friendly month number: 1..12 and will return one of constants:
>> Calendar.JANUARY .... Calendar.DECEMBER
My observation is calendar gives next month
Can i use
int iMonth = Integer.parseInt(strMonth)-1;
Please suggest me.
01-07-2010 04:42 AM
I am making one calender application in which user is able to store their daily events ,and also able to go next and previous month .i am new in blackberry,will u plz help me in order to do this.
01-07-2010 08:15 AM
I don't think it is appropriate to ask new (and unrelated) questions on existing Threads. So if you have a new questions, please start a new Thread.
With respect to this question, there is lot to it. Remember this is a forum to answer technical questions, not a training forum.
In this case I suggest you look at the samples provided by RIM, especially the PIM sample that does some work with the Calendar. Get that working, look at and understand how it works, then you will be in a better position to ask more appropriate questions on this forum
Hope this helps and good luck.
02-03-2011 01:42 AM
I want to convert string date(date format is: dd/MM/yyyy) to Date or long.
I am using calender to store date.
Here is my code:
String strDate = 01/01/2011
Calendar oCalendar = Calendar.getInstance();
oCalendar.set (Calendar.MONTH,01 );
Date oDate = oCalendar.getTime(); -> If convert this date to string it gives me "01/02/2011" instead of original date.
What am I doing wrong?
Thanks & Regards,