作为添加日期的MVC3日期计算

作为添加日期的MVC3日期计算

问题描述:

我正在尝试处理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; } 
} 

var startdate = DateTime.Now.AddDays(2); 

private DateTime _startDate; 


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

}