Reputation: 155
I need to deploy an ASP.NET application written in C# to multiple servers and cannot be sure what the regional settings are. How can I read the current date (DateTime.Today) into a DateTime variable using the server's locale and specify the format that I wish it to be in. This way giving me a consistently formatted date that I can then manipulate as desired.
Upvotes: 0
Views: 1735
Reputation: 100308
using System.Globalization;
DateTime now = DateTime.Today;
string local = now.ToString(CultureInfo.CurrentCulture);
string custom = now.ToString(new CultureInfo("ru-RU"));
Note, that region settings only affects string representation, i.e. format, but not DateTime type itself!
Upvotes: 3