2012-03-18 42 views
0

我正在嘗試處理dateTime。我創建了使用Now()的dateCreated字段。我可以添加其他計算的日期時間字段,它會自動添加兩天。 例如,dateCreated創建於2012年3月18日。我想創建2012年3月20日設置的新dateTime值。是否可以在模型中計算日期? 這是我的代碼。謝謝。作爲添加日期的MVC3日期計算

public class Cart 
{ 
    [Key] 
    public int recordId { get; set; } 
    public string cartId { get; set; } 
    public int productId { get; set; } 
    public int count { get; set; } 
    public DateTime dateCreated { get; set; } 
    // Can I make startDate as adding two days with dateCreated? 
    // Is there any calculation for this? 
    //public DateTime startDate { get; set; } 
    public virtual Product Product { get; set; } 
} 

回答

2
private DateTime _startDate; 


public DateTime StartDate 
{ 
    set { _startDate=value; } 
    get { return dateCreated.AddDays(2); } 

}