网络服务的日期转换问题 [英] Date Conversion issue from webservice

查看:48
本文介绍了网络服务的日期转换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个Web Service,它将在响应对象中返回datetime字段。

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

我的reference.cs文件具有

My reference.cs file has,

private System.DateTime timestampField;

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

在SOAP UI中,当我调用服务时,我看到它是返回为 2014-06-09T21:24:56 + 00:00 ,2014-06-17T05:42:00-04:00

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

但是从我的.NET App调用时,它正在转换为其他值,例如 6/9/2014 5:24:56 PM ,但实际值应为 2014/6/9 9:24 pm

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.

我该如何解决?

推荐答案

此是我所做的,不确定这是否有效。.

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

我将时间字段值转换为字符串,并使用子字符串获取了偏移量,并将其应用于时间字段值的UTC

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);

这篇关于网络服务的日期转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆