我正在使用datepicker来选择日期,
我的addEventlistener源代码就在这里。
$.picker.addEventListener('change',function(e){
var date = e.value;
Ti.API.info(date); // shows '[INFO] : 2014-04-07 21:28:34 +0000' on console
date.substring(0,10);
});
Ti.API.info(日期)显示正确的数据,但是 date.substring(0,10);显示如下所示的错误
[ERROR] : Script Error {
[ERROR] : backtrace = "#0 () at :0";
[ERROR] : line = 143;
[ERROR] : message = "'undefined' is not a function (evaluating 'date.substring(0, 10)')";
[ERROR] : name = TypeError;
[ERROR] : sourceId = 329234912;
[ERROR] : sourceURL = "file:///Users/temp/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/2E7B2C43-653A-4E38-BB04-F820AB2C3BC2/matomato.app/alloy/controllers/index.js";
[ERROR] : }
答案 0 :(得分:2)
将date转换为String,然后您就可以使用substring
了$.picker.addEventListener('change',function(e){
var date = e.value;
date= date.toString(); // check it
date.substring(0,10);
Ti.API.info(date); //'2014-04-07'
});
答案 1 :(得分:1)
您可以使用的日期:
var day = date.getDate();
var month = date.getMonth();
var year = date.getFullYear();
var newdate = year + "-" + month + "-" + day;