Skip to content

Instantly share code, notes, and snippets.

@alanerzhao
Created November 20, 2013 07:54
Show Gist options
  • Save alanerzhao/7559348 to your computer and use it in GitHub Desktop.
Save alanerzhao/7559348 to your computer and use it in GitHub Desktop.
//dataAPI : 'http://roll.news.sina.com.cn/interface/rollnews_ch_out_interface.php',
function Person (name,age,job) {
//防止全局作用域意外对象属性
if(this instanceof Person) {
this.name = name;
this.age = age;
this.job = job;
} else {
return new Person(name,age,job);
}
}
function selectForm(lowerValue,upperValue) {
var choices = upperValue - lowerValue + 1;
return Math.floor(Math.random() * choices + lowerValue);
}
var num = selectForm(2,10);
//console.log(num);
var colors = ['red','green','blue','yellow','black','brown'];
var color = colors[selectForm(0,colors.length-1)];
// console.log(color);
function setsinaData () {
var data = jsonData,
tmpl = '';
i = 0;
len = data.list.length;
for(i;i<len;i++) {
tmpl+="<li><span>--"+data.list[i].channel.title.substring(0,2)+"--</span><a href='"+data.list[i].url+"' target='_blank'>"+data.list[i].title+"</a><span>"+getTimeZoneTime(data.list[i].time)+"</span></li>";
// console.log(data.list[i]);
}
$(document.body).append(tmpl);
}
setsinaData();
function getTimeZoneTime (s) {
if(typeof(s) === 'undefined'){
s = this.dateObj.getTime();
}else{
s = s*1000;
};
console.log(s);
var tempTime = new Date(s);
var year = tempTime.getFullYear();
var month = tempTime.getMonth() + 1;
var date = tempTime.getDate();
var hours = tempTime.getHours();
var minutes = tempTime.getMinutes();
var seconds = tempTime.getSeconds();
//两位
var monthTwoBit = month > 9?month.toString():"0" + month;
var dateTwoBit = date > 9?date.toString():"0" + date;
var hoursTwoBit = hours > 9?hours.toString():"0" + hours;
var minutesTwoBit = minutes > 9?minutes.toString():"0" + minutes;
var secondsTwoBit = seconds > 9?seconds.toString():"0" + seconds;
var str = '';
if(this.year != year){
str = year + '-';
};
return str + monthTwoBit + '-' + dateTwoBit + ' ' + hoursTwoBit + ':' + minutesTwoBit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment