Vlad K
Vlad K

Reputation: 2841

How to convert java.sql.Timestamp to a DateTime?

I'm getting timestamp from a DB as a java.sql.Timestamp .

How to convert it to a Mule DateTime type (org.mule.el.datetime.DateTime) in MEL?

Thanks

Upvotes: 0

Views: 1489

Answers (1)

Craig Bayley
Craig Bayley

Reputation: 81

You can pass in the java.sql.Timestamp into the constructor for the org.mule.el.datetime.DateTime. I use function:now purely to create the current time as that object type in the example below, assigned to a flow variable. Run in debug and you'll see.

So the MEL is: #[new org.mule.el.datetime.DateTime(flowVars.time)]

Here's the example:

<flow name="timeFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/time" doc:name="HTTP"/>
    <set-variable variableName="time" value="#[function:now]" doc:name="Variable"/>
    <set-payload value="#[new org.mule.el.datetime.DateTime(flowVars.time)]" doc:name="Set Payload"/>
    <logger level="INFO" doc:name="Logger"/>
</flow>

Upvotes: 1

Related Questions