Reputation: 2730
I am using date picker in my application
When i click button it take selected date from date picker and set it to text field
set.addEventListener('click',function(e){
textfield.setValue(picker.value);
});
It set date as 2016-02-29 18:30:00 +0000
but i want it as 29-02-2016
How can i change date format?
Upvotes: 0
Views: 1984
Reputation: 73
try this one :
set.addEventListener('click',function(e){
var selectedDate = new Date(e.value);
textfield.setValue(selectedDate.getDate() +"-"+ selectedDate.getMonth() +"-"+ selectedDate.getFullYear());
});
Upvotes: 1
Reputation: 11552
Alternately, you can use var date = new Date(picker.value);
and then use the native Javascript date functions.
Upvotes: 2
Reputation: 740
You can use Momentjs
var moment = require('alloy/moment');
set.addEventListener('click',function(e){
textfield.setValue( moment(picker.value).format("DD-MM-YYYY") )
});
More details
http://docs.appcelerator.com/platform/latest/#!/api/Alloy.builtins.moment
Upvotes: 5