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
Developer
Posts: 358
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus
Accepted Solution

How to retrieve date in a specific format on button clicked?

I'm trying to update the date in a data model on a button clicked, but unfortunately the Date() just gives a long unncesseray format.  I just want Month/Day/Year (i.e. 9/10/2013).  How would I change the Date() function to achieve this?

 

 Button {
                                    leftPadding: 30
                                    rightPadding: 30
                                    preferredWidth: 150
                                    horizontalAlignment: HorizontalAlignment.Center
                                    imageSource: "asset:///images/ic_add.png"
                                    onClicked: {
                                        
                                        rootItem.ListItem.view.getApp().updateObject(ListItemData.customerID, ListItemData.name, ListItemData.description, Date(), parseInt(ListItemData.lat) + 1, ListItemData.lon, ListItemData.categorySelect, ListItemData.mapurl)
                                    }
                                } 

 Thanks in advance.  Likes and solutions will be given for those who help.

 

regards,

Brandon

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How to retrieve date in a specific format on button clicked?

Similar thread here...

 

http://supportforums.blackberry.com/t5/Native-Development/Format-a-Date-in-QML/td-p/1955083


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 358
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus

Re: How to retrieve date in a specific format on button clicked?

I was actually able to find a simpler work-around.  I simply used attached objects within the button and attached a date function:

 

Button {
                                    
                                    imageSource: "asset:///images/ic_add.png"
                                    onClicked: {
                                        
                                        rootItem.ListItem.view.getApp().updateObject(ListItemData.customerID, ListItemData.name, ListItemData.description, datefield3.text, parseInt(ListItemData.lat) + 1, ListItemData.lon, ListItemData.categorySelect, ListItemData.mapurl)
                                        
                                    }
                                    attachedObjects: [
                                        Label {
                                            id: datefield3
                                            text: {
                                                var today = new Date();
                                                (today.getMonth() + 1) + "/" + today.getDate() + "/" + (today.getFullYear() - 2000);
                                            }
                                            
                                        }
                                    ]
                                }