ConvertToLocal return kind

Mar 23, 2010 at 1:18 PM

Kinda new to the handling of international dates so not 100% sure on this one so thought I'd ask ...

When creating the offset local date from a UTC or Unspecified date should the return date be of kind "Local" rather than Utc?

Here's the snippet:

 

public DateTime ConvertToLocal(DateTime dt)
        {
            // The the kind is Local already then use this.
            // Else just assume it is UTC even if not specified
            if (dt.Kind == DateTimeKind.Local)
            {
                return dt;
            }

            // Now just add the standard offset
            return new DateTime((dt + GetUtcOffset(dt)).Ticks, DateTimeKind.Utc);
        }

 

 

 Great work on this library btw.

 

Mar 23, 2010 at 2:20 PM

Hi Daniel - glad you've stopped by :)

er ... I have absolutely no idea :( Because, I don't know what this 'Kind' thingy is :(

Can u try asking on StackOverflow.com ? And link the question, to here ?

Coordinator
Mar 23, 2010 at 11:04 PM

Hi Daniel,

Yes I think you are right about this one.

Can you copy it to a work item? I am about to upgrade to the VS2008 so planning on including a lot of Purekrome's changes in the next release.

Glad you find the library useful.

Mark

Jul 2, 2011 at 7:37 AM

Starting with version 2.0 of the .NET Framework, it includes a Kind property that provides limited information about the time zone to which that date and time belongs. The DateTimeKind value returned by the Kind property indicates whether the DateTime value represents the local time (DateTimeKind.Local), Coordinated Universal Time (UTC) (DateTimeKind.Utc), or an unspecified time (DateTimeKind.Unspecified).

 

reference link is here... http://msdn.microsoft.com/en-us/library/bb384267.aspx .. worth quick read