Saturday, July 2, 2011

Localization of Dates in C#

To store current date as UTC in sql server, sql GETUTCDATE() function can be used( in your storedproc).
Note that GETUTCDATE() returns the current datetime in UTC.
In your codebehind you can use the C# ToLocalTime function method to restore a local date and time value that was converted to UTC
example:
DateTime date1 = new DateTime(2011, 4, 13, 2, 30, 0, DateTimeKind.Local);
DateTime utcDate1 = date1.ToUniversalTime();
DateTime date2 = utcDate1.ToLocalTime();

No comments:

Post a Comment

Open default email app in .NET MAUI

Sample Code:  if (Email.Default.IsComposeSupported) {     string subject = "Hello!";     string body = "Excellent!";    ...