Skip to content

Instantly share code, notes, and snippets.

@alanerzhao
Created May 19, 2014 08:44
Show Gist options
  • Save alanerzhao/8359d87b0d0e559b3756 to your computer and use it in GitHub Desktop.
Save alanerzhao/8359d87b0d0e559b3756 to your computer and use it in GitHub Desktop.
//表情除理
function replace_em(str){
str = str.replace(/\</g,'&lt;');
str = str.replace(/\>/g,'&gt;');
str = str.replace(/\n/g,'<br/>');
str = str.replace(/\[em_([0-9]*)\]/g,'<img src="face/$1.gif" border="0" />');
return str;
}
//处理时间
function format (date,format) {
var curDate = new Date(date);
var date = {
"M+": curDate.getMonth() + 1,
"d+": curDate.getDate(),
"h+": curDate.getHours(),
"m+": curDate.getMinutes(),
"s+": curDate.getSeconds(),
"q+": Math.floor((curDate.getMonth() + 3) / 3),
"S+": curDate.getMilliseconds()
};
if (/(y+)/i.test(format)) {
format = format.replace(RegExp.$1, (curDate.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (var k in date) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1
? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
}
}
return format;
}
//格式化时间
var d = format(obj.time_stamp,'yyyy-MM-dd hh:mm:ss')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment