简体   繁体   English

使用DataWeave 1.0在Mule-3.8.4中转换为SalesForce日期时间格式

[英]Converting to SalesForce datetime format in Mule-3.8.4 using DataWeave 1.0

I am trying to convert a datetime column in a CSV to a salesforce datetime format to do an upsert. 我正在尝试将CS​​V中的datetime列转换为salesforce日期时间格式以执行upsert。 I tried expression like below in mule-3.8.4 dataweave1.0 but I am getting an error. 我在mule-3.8.4 dataweave1.0中尝试过如下表达,但是我收到了一个错误。

I tried the following: 我尝试了以下方法:

First Try 第一次尝试

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" })

Expected Output : 2019-01-14T06:31:00Z 预期产量 :2019-01-14T06:31:00Z

Actual Output : Mon Jan 14 18:31:00 EST 2019 实际产出 :1月14日星期一,2019年东部时间18:31:00

After Upsert in Salesforce, it looks like this: 2019-01-14T00:00:00.000+0000 . 在Salesforce中Upsert后,它看起来像这样: 2019-01-14T00:00:00.000+0000 It is not saving the time. 它不节省时间。


Second Try 第二次尝试

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" })

Expected Output : 2019-01-14T06:31:00 预期产出 :2019-01-14T06:31:00

Actual Output : Mon Jan 14 18:31:00 EST 2019 实际产出 :1月14日星期一,2019年东部时间18:31:00

After Upsert in Salesforce, it looks like this: 2019-01-14T00:00:00.000+0000 . 在Salesforce中Upsert后,它看起来像这样: 2019-01-14T00:00:00.000+0000 It is still not saving the time. 它仍然没有节省时间。

What is the problem? 问题是什么?

To format a date, the format pattern reading left to right, needs to match your expected output. 要格式化日期,从左到右读取的格式模式需要与预期输出匹配。 So for your example: 所以对于你的例子:

2019-01-14T06:31:00Z 2019-01-14T06:31:00Z

yyyy-MM-dd'T'HH:mm:ssZ YYYY-MM-dd'T'HH:MM:SSZ

y is for year M is for Month(lowercase m is for minute y代表年份M代表月份(小写字母m代表分钟

d is for day d是一天

H is for hour in 24 hr format. H是24小时格式的小时。 (Lowercase would be 12 be format) (小写将是12格式)

S is for milliseconds S是毫秒

And Z is time zone There's more you can configure for time zone and milliseconds if needed. Z是时区如果需要,您可以配置更多的时区和毫秒。

Here are the salesforce date format info: 以下是salesforce日期格式信息:

https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/datafiles_date_format.htm https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/datafiles_date_format.htm

More date format info: 更多日期格式信息:

https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Have you tried sending it to Salesforce as a String ? 您是否尝试将其作为String发送到Salesforce? Once something is of type LocalDateTime , there is no further formatting it. 一旦类型为LocalDateTime ,就没有进一步的格式化。 The formatting is solely for the purpose of parsing a String into a LocalDateTime or formatting the output of a LocalDateTime to a String . 格式仅仅是为了解析的目的StringLocalDateTime或的输出格式化LocalDateTime到一个String For example: 例如:

"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

If you want to take one String representing a datetime and format it to a different String representing the same datetime, you could do this: 如果要获取一个表示日期时间的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

Output of that last script should be "2019-01-14T18:31:00" 最后一个脚本的输出应为"2019-01-14T18:31:00"

Finally below code worked. 最后下面的代码工作。 Mule Dataweave converted the following format(yyyy-MM-dd'T'HH:mm:ss.SSSZ) to java.util.Calendar Object. Mule Dataweave将以下格式(yyyy-MM-dd'T'HH:mm:ss.SSSZ)转换为java.util.Calendar对象。

Test_Date: "1/22/19 6:31 PM" as :localdatetime { format: "M/dd/yy h:mm a" } as :datetime { format: "yyyy-MM-dd'T'HH:mm:ss.SSSZ" }) Test_Date:“1/22/19 6:31 PM”as:localdatetime {format:“M / dd / yy h:mm a”} as:datetime {format:“yyyy-MM-dd'T'HH:mm: ss.SSSZ“})

This is how the Payload looks after Transform Message in DataWeave(above step): 这是Payload在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,HOUR=4,HOUR_OF_DAY=18,MINUTE=31,SECOND=0,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0] Test_Date = java.util.GregorianCalendar中[时间= ?, areFieldsSet =假,areAllFieldsSet =真,宽大=真,区= sun.util.calendar.ZoneInfo [ID = “GMT”,偏移= 0,dstSavings = 0,useDaylight =假,过渡= 0,lastRule =空],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,HOUR = 4,HOUR_OF_DAY = 18,MINUTE = 31,SECOND = 0,微差= 0,ZONE_OFFSET = 0,DST_OFFSET = 0]

Output after Upsert in SalesForce : 2019-01-22T18:31:00.000+0000 SalesForce中Upsert后的输出:2019-01-22T18:31:00.000 + 0000

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

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