简体   繁体   English

如何将日期时间变量从C#代码传递给java webservice?

[英]How to pass datetime variable from C# code to java webservice?

getClients(LoginInfo user, long sysId, java.lang.String accNum, java.lang.String ClientNum, java.util.Calendar fromTime, java.util.Calendar toTime, boolean showDeactivated, boolean showDetails).

Above is java webservice method that I am calling from C# code. 以上是我从C#代码调用的java webservice方法。

I am passing fromTime and ToTime parameters with following values 我使用以下值传递Time和ToTime参数

 DateTime from = new DateTime(2012, 3, 1, 1, 1, 1, DateTimeKind.Unspecified);
 DateTime to = new DateTime(2012, 4, 1, 1, 1, 1, DateTimeKind.Unspecified);

Found an error date string can not be less than 19 charactors 发现错误date string can not be less than 19 charactors

Edit_ _ __ _ __ _ __ _ __ _ __ _ __ _ ___ * Below is method in proxy * Edit_ _ __ _ __ _ __ _ __ _ __ _ __ _ ___ * 以下是代理方法 *

getClients([System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] 
LoginInfo user, long sysId, [System.Xml.Serialization.XmlIgnoreAttribute()] bool sysdSpecified, 
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] string accNum, 
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] 
string ClientNum, [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] 
System.Nullable<System.DateTime> fromTime, [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] 
[System.Xml.Serialization.XmlIgnoreAttribute()] bool fromTimeSpecified,
 [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] System.Nullable<System.DateTime> toTime,
 [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] 
[System.Xml.Serialization.XmlIgnoreAttribute()] 
bool toTimeSpecified, 
bool showDeactivated, [System.Xml.Serialization.XmlIgnoreAttribute()]
 bool showDeactivatedSpecified, bool showDetails, 
[System.Xml.Serialization.XmlIgnoreAttribute()] bool showDetailsSpecified) {
}

Why don't you convert the value to a long? 为什么不将值转换为长? For example: minutes from 01/01/1990. 例如:1990年1月1日的分钟数。

Send from C# as: 从C#发送:

private static readonly DateTime Jan1st1970 = new DateTime
    (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

public static long CurrentTimeMillis()
{
    return (long) (DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
}

Recieve in Java as: 在Java中接受:

new Date(longValueFromAbove);

Have you tried using DateTimeKind.UTC? 你尝试过使用DateTimeKind.UTC吗?

The string is probably missing the time zone specifier, when you use DateTimeKind.Unspecified. 使用DateTimeKind.Unspecified时,字符串可能缺少时区说明符。

EDIT: OK, DateTime is not providing the timezone by any means, but DateTimeOffset does it. 编辑:好的,DateTime没有以任何方式提供时区,但DateTimeOffset做到了。 Try this: 试试这个:

  new DateTimeOffset(yourDateTime)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM