1

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..

Jeyhun Rahimov
  • 3,769
  • 6
  • 47
  • 90

2 Answers2

5

DateTime.Now will 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.UtcNow instead - this will give you a consistent result wherever the computer is (assuming the computer is correctly setup).

Oded
  • 489,969
  • 99
  • 883
  • 1,009
2

DateTime.Now depends on the computer it's run on. That means, if you deploy a web application, DateTime.Now returns a DateTime set on that server. It won't return different values for different users, because C# runs on the server-side and isn't affected by a client.

walther
  • 13,466
  • 5
  • 41
  • 67