In mvc3 application when I create new product, I want to add it’s create date.
[HttpPost]
public ActionResult Create( Product product )
product.CreateDate = DateTime.Now.ToLongDateString();
...
return View( product );
}
When I will deploy site to hosting, will DateTime.Now create any problem? Does it depend on user’s computers time? If user’s computer time is not correct, product’s create date will be incorrect..I need help about this, always to get real time. Or, advise other way, please. Sorry for my bad english..
DateTime.Nowwill reflect the date and time on the computer that the code is running on (so, in a web application, the server time).I suggest using
DateTime.UtcNowinstead – this will give you a consistent result wherever the computer is (assuming the computer is correctly setup).