我试图以整数形式返回今天的日期。我尝试将其作为字符串返回,并且工作正常。但我如何将其作为整数返回?
public string ConvertInvoiceDate()
{
return DateTime.Today.ToString("yyyyMMdd");
}
整数的格式应与 yyyyMMdd 相同。这里的返回类型是字符串,因为我正在尝试使用字符串。现在我不确定是否必须返回 long/double。使用 BizTalk,我尝试将值插入到 Oracle DB 中类型为数字的字段中。当我尝试以字符串形式返回时,它抛出错误为
The value for field "INVOICE_DTE" is invalid. ---> System.FormatException: The string '20170626' is not a valid AllXsd value.
DB中字段详细信息如下
完整的错误消息是
A message sent to adapter "WCF-Custom" on send port "WcfSendPort_OracleDBBinding_Table_MACINVOICE_Custom" with URI "oracledb://xxxxx/" is suspended.
Error details: Microsoft.ServiceModel.Channels.Common.XmlReaderParsingException: The value for field "INVOICE_DTE" is invalid. ---> System.FormatException: The string '20170626' is not a valid AllXsd value.
at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)
at System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption)
at Microsoft.Adapters.OracleCommon.OracleCommonMetadataUtils.ConvertXmlToLob(String text, XmlTypeCode xmlTypeCode, QualifiedType qualifiedType, String fieldName)
--- End of inner exception stack trace ---
Server stack trace:
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndRequest(IAsyncResult result)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at System.ServiceModel.Channels.IRequestChannel.EndRequest(IAsyncResult result)
at Microsoft.BizTalk.Adapter.Wcf.Runtime.WcfClient`2.RequestCallback(IAsyncResult result)
MessageId: {449B56A2-B053-47A4-826A-400B97CFB9A1}
InstanceID: {DEA7CAA7-D589-4A4E-81A0-A2C6A961D340}
只需在返回之前将它们转换为整数,如下所示:
public int ConvertInvoiceDate()
{
return int.Parse(DateTime.Today.ToString("yyyyMMdd"));
}
正如 Panagiotis Kanavos 在评论中所说,XML 字段可能被定义为使用 ISO8601 格式的 xsd::datetime,即
2017-06-23T13:14:15Z
要实现此目的,您可以执行以下操作,或者更简单地将日期时间 functoid 连接到地图中的节点。
public string ConvertInvoiceDate()
{
return DateTime.Today.ToString("o");
}
再试一次
int.Parse(DateTime.Today.ToShortDateString().Replace("-",""))
如果你正在寻找 DateTime 对象的数值,有一个属性 Ticks,但它是 long 类型,而不是 int。
https://msdn.microsoft.com/ru-ru/library/system.datetime.ticks(v=vs.110).aspx