js读取mongodb日期加8个月,再更新数据

来源:互联网 发布:腾讯手机管家数据恢复 编辑:程序博客网 时间:2024/05/17 02:34
function Todate(num) { //Mon Jan 01 2001 00:00:00 GMT+0800  num=num+"";  print(num);            var date = "";            var month = new Array();            month["Jan"] = "01"; month["Feb"] = "02"; month["Mar"] = "03"; month["Apr"] = "04"; month["May"] = "05"; month["Jun"] = "06";            month["Jul"] = "07"; month["Aug"] = "08"; month["Sep"] = "09"; month["Oct"] = "10"; month["Nov"] = "11"; month["Dec"] = "12";var str = num.split(" ");            date = str[3] + "-" + month[str[1]] + "-" + str[2]+" "+str[4];            print(date);            return date;        }function padNumber(n) {return (n < 10 ? '0' : '') + n;}function isoDate(msSinceEpoch) {var d = new Date(msSinceEpoch);return d.getUTCFullYear() + '/' + padNumber(d.getUTCMonth() + 1) + '/' + padNumber(d.getUTCDate()) + ' ' +padNumber(d.getUTCHours()) + ':' + padNumber(d.getUTCMinutes()) + ':' + padNumber(d.getUTCSeconds()) + '.0';}function increaseDataMonth(collection, changeMonth) {//var changeMonth = 8;//var collection = db.ding;collection.find().forEach(function (e, i) {var oldtime = ISODate(e.lastchanged);var newtime = oldtime;newtime.setMonth(oldtime.getMonth() + changeMonth);e.lastchanged = isoDate(newtime);collection.save(e);})}function increaseDataMonth2(collection, changeMonth) {collection.find().forEach(function (e) {  var ok=Todate(e.lastchanged);var oldtime = ISODate(ok);var newtime = oldtime;newtime.setMonth(oldtime.getMonth() + changeMonth);ok = isoDate(newtime);collection.update({"_id":e._id},{$set:{"lastchanged":ok}});//    })}//use sharkExtermalBackUp;increaseDataMonth2(db.testSparktime, 8);////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   function Todate(num) { //2015/3/13 08:35:05  num=num+"";  print(num);            var date = "";var str = num.split("/");var month=str[1];if(month<10){month="0"+month;}var str2 = num.split(" ")[0];print(str2+" str2");var str3 = str2.split("/");var day=str3[2];if(day<10){day="0"+day;}print(day+"   day");            date = str[0] + "-" + month + "-" + day+" "+num.split(" ")[1];            print(date);            return date;        }function padNumber(n) {return (n < 10 ? '0' : '') + n;}function isoDate(msSinceEpoch) {var d = new Date(msSinceEpoch);return d.getUTCFullYear() + '/' + (d.getUTCMonth() + 1) + '/' + d.getUTCDate() + ' ' +padNumber(d.getHours()) + ':' + padNumber(d.getUTCMinutes()) + ':' + padNumber(d.getUTCSeconds()) + '';}function hufan(collection, changeMonth) {  print(11111111111111111);collection.find().forEach(function (e) {  print(e.lastchanged+"   lastchanged");  var ok=Todate(e.lastchanged);  print(ok+" ok");var oldtime = ISODate(ok);var newtime = oldtime;newtime.setMonth(oldtime.getMonth() + changeMonth);print(newtime+"  newtime");e.lastchanged = isoDate(newtime);print(e.lastchanged+"  end");collection.update({"_id":e._id},{$set:{"lastchanged":e.lastchanged}});})}hufan(db.e3_order_goods_etl, 8);///////////////////////////////////////////////////////////////////////////////////////////////function padNumber(n) {return (n < 10 ? '0' : '') + n;}function isoDate(msSinceEpoch) {var d = new Date(msSinceEpoch);return d.getUTCFullYear() + '-' + (d.getUTCMonth() + 1) + '-' + d.getUTCDate() + ' ' +padNumber(d.getHours()) + ':' + padNumber(d.getUTCMinutes()) + ':' + padNumber(d.getUTCSeconds()) + '.0';}function hufan(collection, changeMonth) {collection.find().forEach(function (e) {  var ok=e.lastchanged;var oldtime = ISODate(ok);var newtime = oldtime;newtime.setMonth(oldtime.getMonth() + changeMonth);e.order_created_earliest = isoDate(newtime);collection.update({"_id":e._id},{$set:{"lastchanged":e.order_created_earliest}});})}hufan(db.e3_order_goods, 8);

0 0
原创粉丝点击