我希望从mongodb
开始一年到头。
这是我的简单脚本:
DateTime sDate = DateTime.SpecifyKind(new DateTime(2013, 1, 15, 00, 00, 00), DateTimeKind.Utc);
DateTime eDate = DateTime.SpecifyKind(new DateTime(2014, 12, 31, 23, 59, 59), DateTimeKind.Utc);
string map = @ "function(){
emit (_id.OwnerId, _id.Date {
Date: Value.Date.getYear(),
PurchaseAmount: parseFloat(Value.PurchaseAmount),
PurchaseReturnAmount: parseFloat(Value.PurchaseReturnAmount),
TotalAmount: parseFloat(Value.TotalAmount)
});
}";
string reduce = @ "function (key, values) {
var outValue = {purchsaeAmount:0 , purchaseReturnAmount:0, totalAmount:0 }
values.forEach(function (value) {
outValue.PurchaseAmount +=parseFloat(value.PurchaseAmount);
outValue.PurchaseReturnAmount +=parseFloat(value.PurchaseReturnAmount);
outValue.TotalAmount +=parseFloat(value.TotalAmount);
});
return outValue;
}";
在地图中我想只获得一年,我怎样才能获得开始年份(2013年)和结束年度(2014年)?
答案 0 :(得分:3)
var d = new Date();
var n = d.getFullYear();
var next_year = d.getFullYear()+1
出:
2013 2014