我正在尝试将 CSV 中的datetime
列转换为 salesforce 日期时间格式以进行更新。我在 mule-3.8.4 dataweave1.0 中尝试了如下表达式,但出现错误。
我尝试了以下方法:
第一次尝试
Test_Date: "1/14/19 6:31 PM" as :localdatetime { format: "M/dd/yy h:mm a" } as :localdatetime { format: "YYYY-MM-DD'T'hh:mm:ssZ" })
预期输出:2019-01-14T06:31:00Z
实际输出:美国东部时间2019年1月14日星期一18:31:00
在 Salesforce 中的 Upsert 之后,它看起来像这样:2019-01-14T00:00:00.000+0000
。它没有节省时间。
第二次尝试
Test_Date: "1/14/19 6:31 PM" as :localdatetime { format: "M/dd/yy h:mm a" } as :localdatetime { format: "YYYY-MM-DD'T'hh:mm:ss" })
预计输出:2019-01-14T06:31:00
实际输出:美国东部时间2019年1月14日星期一18:31:00
在 Salesforce 中的 Upsert 之后,它看起来像这样:2019-01-14T00:00:00.000+0000
。它仍然没有节省时间。
问题出在哪里?
要设置日期格式,格式模式从左到右读取,需要与预期的输出相匹配。所以对于你的例子:
2019-01-14T06:31:00Z
yyyy-MM-dd'T'HH:mm:ssZ
y 代表年份 M 代表月份(小写 m 代表分钟
d 代表天
H 表示 24 小时格式的小时。(小写将是 12 是格式)
S 表示毫秒
Z 是时区 如果需要,您可以为时区和毫秒配置更多内容。
以下是销售队伍日期格式信息:
https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/datafiles_date_format.htm
更多日期格式信息:
https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
您是否尝试过将其作为String
发送到Salesforce?一旦某些内容是LocalDateTime
类型,就没有进一步的格式化。格式化仅用于将String
解析为LocalDateTime
或将LocalDateTime
的输出格式化为String
。例如:
"1/14/19 6:31 PM"
as :localdatetime { format: "M/dd/yy h:mm a" } // This parses the string as LocalDateTime
as :localdatetime { format: "YYYY-MM-DD'T'hh:mm:ssZ" } // This doesn't do anything, it's already LocalDateTime
如果要采用一个表示日期时间String
并将其格式化为表示相同日期时间的不同String
,则可以执行以下操作:
...
%var inputFormat = "M/dd/yy h:mm a"
%var outputFormat = "yyyy-MM-dd'T'HH:mm:ss"
---
"1/14/19 6:31 PM"
as :localdatetime { format: inputFormat } // Used to parse the input string
as :string { format: outputFormat } // Used to format the output string
最后一个脚本的输出应"2019-01-14T18:31:00"
最后下面的代码起作用了。 Mule Dataweave 转换了以下格式(yyyy-MM-dd'T'HH:mm:ss.SSSZ) 到 java.util.Calendar Object。
Test_Date: ">1/22/19 6:31 PM" 作为 :localdatetime { format: "M/dd/yy h:mm a" } as :d atetime { format: "yyyy-MM-dd'T'HH:mm:ss.SSSZ" })
这是有效负载在DataWeave中转换消息后的样子(上述步骤):
Test_Date=java.util.GregorianCalendar[time=?,areFieldsSet=false,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings = 0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2019,MONTH=0,WEEK_OF_YEAR=13,WEEK_OF_MONTH=5,DAY_OF_MONTH=22,DAY_OF_YEAR=84,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,小时=4,HOUR_OF_DAY=18,分钟=31,秒=0,毫秒=0,ZONE_OFFSET=0,DST_OFFSET=0]
SalesForce 中更新插入后的输出:2019-01-22T18:31:00.000+0000