Search code examples
c#web-servicesdatetimeproxy-classes

Date Conversion issue from webservice


I am consuming a Web Service which will return datetime fields in response object.

My reference.cs file has,

private System.DateTime timestampField;

public System.DateTime Timestamp {
    get {
        return this.timestampField;
    }
    set {
        this.timestampField = value;
    }
}

In SOAP UI when I called the service I see it's returning as 2014-06-09T21:24:56+00:00 , 2014-06-17T05:42:00-04:00

I have different Offsets for Different values..

But from my .NET App when I am calling it's converting to some other value as 6/9/2014 5:24:56 PM but it should be whose actual value is 6/9/2014 9:24 pm.

How can I fix this?


Solution

  • This is what I did, not sure if it's the efficient way..

    I had different offset values for different time values and I don't know the timezone from the time field value... what I did is

    I converted the time field value to string and got the offset using sub string and applied that to the UTC of time field value

         TimeSpan offSetSpan = new TimeSpan();
              string dt = TimestampValue;
              string offset = TimestampValue.Substring(trackevent.Timestamp.Length - 6,6);
    
              if (offset != "+00:00" && offset != "-00:00")
                                    {
                                        offSetSpan = TimeSpan.Parse(offset.Trim());
                                    }
    Console.WriteLine("Offset Timestamp: {0}", Convert.ToDateTime(TimestampValue).ToUniversalTime() + offSetSpan);