郭卫东

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);

//显示时间结束

posted on 2014-11-19 22:14  郭卫东  阅读(178)  评论(0编辑  收藏  举报

导航