mongodb格式化日期(yyyyMMdd)
db.purchase_history.find().forEach(
function(item){
var ds= db.purchase_history.find({"_id":item._id},{"createTime":1});
var dschilds=ds.toArray();
var temp = dschilds[0].createTime;
var id = dschilds[0]._id;
function tran_val(val){
if(val<10){
val="0" +val;
}
return val;
}
var datenew = new Date(temp);
var year=datenew.getFullYear();
var month=tran_val(datenew.getMonth()+1);
var date=tran_val(datenew.getDate());
var datestr=year+""+month+""+date;
db.purchase_history.update({"_id": id},{$set:{"completedate" :datestr}},true);
}
)
将时间戳格式的createTime格式化为年月日格式的completedate