You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将系统日期转为指定Timestamp格式并传递至第三方服务器报错求助

问题描述

需要将Oracle系统日期转换为**2022-09-23T15:38:47.6927242-05:00**格式的时间戳,传递给第三方Aramex的Shipping API。使用select systimestamp from dual获取时间戳后,请求时报错,错误信息如下:

服务器处理请求时出错。请查看服务帮助页面构造有效请求。异常消息为:'格式化程序尝试反序列化消息时抛出异常:反序列化参数http://ws.aramex.net/ShippingAPI/v1/:Shipments时出错。内部异常消息为:'反序列化类型System.Collections.Generic.List`1[[Corp.ShippingAPI.FrontEnd.Contracts.Shipment, Corp.ShippingAPI.FrontEnd.Contracts, Version=1.287.0.0, Culture=neutral, PublicKeyToken=null]]的对象时出错。值''无法解析为'DateTime'类型。'。请查看内部异常了解更多详细信息。'。有关详细信息,请查看服务器日志。异常堆栈跟踪:
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContext

问题原因

systimestamp返回的是Oracle原生的TIMESTAMP WITH TIME ZONE类型,直接传递时未被正确序列化为API要求的字符串格式,甚至出现空值,导致第三方API无法解析为DateTime类型。

解决方案

使用Oracle的TO_CHAR函数将systimestamp显式格式化为目标字符串:

SELECT TO_CHAR(systimestamp, 'YYYY-MM-DD"T"HH24:MI:SS.FF7TZH:TZM') AS formatted_timestamp
FROM dual;

格式参数说明

  • YYYY-MM-DD:年-月-日结构
  • "T":固定分隔符,用双引号包裹避免被解析为格式控制符
  • HH24:MI:SS:24小时制的时:分:秒
  • FF7:保留7位小数的毫秒部分(匹配示例精度)
  • TZH:TZM:时区偏移格式(如-05:00)

执行该语句后,会返回完全符合要求的时间戳字符串,将其直接填入请求payload对应的字段即可解决反序列化错误。

内容的提问来源于stack exchange,提问作者Adeel Aslam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 16:50:44