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

Native Development

Reply
Regular Contributor
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone
Accepted Solution

convert date format from english to arabic

hi

 

i am making an app, where i am getting date from server in this format

 

21/8/2013

 

i want to display this date in arabic format like

 

date.png

 

 

can anybody help me ?

does Qlocale help me in this conversion ?

any sample for that

Regular Contributor
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone

Re: convert date format from english to arabic

thanks for co-operation 

 

i have it using javascript function :smileyhappy:

Regular Contributor
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone

Re: convert date format from english to arabic

i have done using the following code

 

 

// Date Label
                            Label {                                
                                function convertDate(dateToBeConverted)
                                
                                {
                                    var digits=["۰","۱","۲","۳","۴","۵","۶","۷","۸","۹"];
                                    var months=["يناير","فبراي","مارس","أبريل","مايو","يونيو","يوليو","أغسطس","سبتمبر","أكتوبر","نوفمبر","ديسمبر"];
                                    console.log("starting date -----> " + dateToBeConverted);   
                                    console.log("type of starting date: " + typeof dateToBeConverted);
                                    dateToBeConverted= dateToBeConverted.replace(/\s+/g, '');
                                    var dateToBeConvert_parts = dateToBeConverted.split('/')
                                    var date_part = dateToBeConvert_parts[0]
                                    var months_part = dateToBeConvert_parts[1]
                                    var year_part = dateToBeConvert_parts[2]
                                    console.log("type of year_part date: " + date_part);

                                    
                                    
                                    
                                    var date_int=parseInt(date_part,10);
                                    var month_int=parseInt(months_part,10);
                                    var year_int=parseInt(year_part,10);
                                    console.log("iii date: " + date_int);
                                    console.log("type of iii date: " + typeof date_int);
                                    
                                    
                                    /*Math.floor(N / (Math.pow(10, n)) % 10)
                                     where N is the number to be extracted, and n is the position of the digit. 
                                     Note that this counts from 0 starting from the right 
                                     (i.e., the least significant digit = 0),
                                     and doesn't account for invalid values of n.*/
                                    
                                    var date_converted=date_int+''
                                    var month_converted=month_int+''
                                    var year_converted=year_int+''
                                    //   var year_=Math.floor( convert_int/ (Math.pow(10, 0)) % 10);
                                    //  var year_=convert_int+'';
                                    //        console.log("date_------>: "+year_ );
                                    // for converting date
                                    for(var b=0; b<2;b++)
                                    {                                   
                                        for (var a = 0; a<10; a++)
                                        {
                                            if(Math.floor(date_int / (Math.pow(10, b)) % 10)==a)
                                            {
                                                date_converted=date_converted.replace(''+a,''+digits[a]);
                                                console.log("year digits"+date_converted);
                                            }
                                        }
                                    }						
                                    
                                    // for months
                                    
                                    for(var c =0;c<13;c++)
                                    {
                                        if(Math.floor(month_int / (Math.pow(10, 0)) % 10)==c)
                                        {
                                            month_converted=month_converted.replace(''+c,''+months[c-1]);
                                            console.log("month digits"+month_converted);
                                        }
                                    }
                                    
                                    // for converting year
                                    for(var d=0; d<4;d++)
                                    {                                   
                                        for (var e = 0; e<10; e++)
                                        {
                                            if(Math.floor(year_int / (Math.pow(10, d)) % 10)==e)
                                            {
                                                year_converted=year_converted.replace(''+e,''+digits[e]);
                                                console.log("year digits"+year_converted);
                                            }
                                        }
                                    }						
                                    

                                    return date_converted+" " + month_converted+" "+year_converted;
                                }