2013-01-16 128 views
0

我想從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)?

回答

3
var d = new Date(); 
var n = d.getFullYear(); 
var next_year = d.getFullYear()+1 

出來:

2013 2014 
相關問題