JSON、数组、时间戳

// on removeClass addClass slice
$('.pic-subgroup').on('click',function(){
$('.pic_div.active').removeClass('active');
$(this).addClass('active');
var src = $(this).children('img').attr('src');
var title=$(this).children('img').attr('title');
src = src.slice(0,src.lastIndexOf('s'))+'l'+src.slice(src.lastIndexOf('s')+1);
$('.max-pic img').attr('src',src);
$('.max-pic img').attr('title',title);
});

//字符串转数组 [{..},{..}] ---> array[]
JSON.parse(strify);


//数组 转 字符串 array[] ---> [{..},{..}] 
JSON.stringify(array);


//数组 赋值 创建
var array=[];
for(var i=0;i<10;i++){
array[i]={}; //*****
array[i]["lat"]="sdas";
}

 

// 时间戳转换 (函数)
function formatDateTime(inputTime) { 
var date = new Date(inputTime); 
var y = date.getFullYear(); 
var m = date.getMonth() + 1; 
m = m < 10 ? ('0' + m) : m; 
var d = date.getDate(); 
d = d < 10 ? ('0' + d) : d; 
var h = date.getHours(); 
h = h < 10 ? ('0' + h) : h; 
var minute = date.getMinutes(); 
var second = date.getSeconds(); 
minute = minute < 10 ? ('0' + minute) : minute; 
second = second < 10 ? ('0' + second) : second;
return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second; 
};

 

posted @ 2017-06-30 16:23  低调人生  阅读(1196)  评论(0编辑  收藏  举报