Divyesh Savaliya
Divyesh Savaliya

Reputation: 2730

Titanium Appcelerator date format

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

Answers (3)

David Loekito
David Loekito

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

Hans Knöchel
Hans Knöchel

Reputation: 11552

Alternately, you can use var date = new Date(picker.value); and then use the native Javascript date functions.

Upvotes: 2

abada henno
abada henno

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

http://momentjs.com/docs/

Upvotes: 5

Related Questions