Titanium系列--利用js动态获取当前时间

动态获取时间:

//显示时间

function getDateTime() {

var now = new Date();

var year = now.getFullYear();

var month = now.getMonth()+1;

var day = now.getDate();

//var hour = now.getHours();

//var minute = now.getMinutes();

//var second = now.getSeconds();

if(month.toString().length == 1) {

var month = ‘0‘+month;

}

if(day.toString().length == 1) {

var day = ‘0‘+day;

}

/*

if(hour.toString().length == 1) {

var hour = ‘0‘+hour;

}

if(minute.toString().length == 1) {

var minute = ‘0‘+minute;

}

if(second.toString().length == 1) {

var second = ‘0‘+second;

}*/

var dateTime = year+‘年‘+month+‘月‘+day+‘日‘;//+hour+‘:‘+minute+‘:‘+second;

return dateTime;

}

var label_time = Titanium.UI.createLabel({

color: ‘white‘,

font: { fontSize:12 },

text:getDateTime(),

top:‘7%‘,

right:‘3%‘

});

main_win.add(label_time);

//显示时间结束

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。