Change DateTime format

#1

Hi @ all,
at the moment I'm coming not to the solution about that.
How could I change the format 2018-12-13T07:03:00.000+0000
only to the time? (In that case to 07:03 or 7.30). Would be
great for any kind of help.

0 Likes

#2

You can do this in several ways
One of them is to use a JSONata expression in a change node that will pick out a part of a payload

something like thisimage

replace start with a number that picks out the 0 from 07: and change length to be how many characters you want (5)

0 Likes

#3

Where is that coming from and what type is it? Is it a string or a Unix timestamp or what?

0 Likes

#4

Hi Colin,
it is coming from openhab and it is a DateTime type.
(openhab.0.items.astro_sun_home_rise_start)

0 Likes

#5

Not sure what you mean by coming from openhab as I don't use openhab. Perhaps the best thing is to feed it into a debug node and show us a screenshot of the result.

0 Likes

#6

Hi attached my screenshot.

0 Likes

#7

I meant a screenshot of what you see in the debug node.
[Edit] so what is in the debug pane

0 Likes

#8

I'm sorry...

0 Likes

#9

Hi cymplecy ,
i try that but didn't work.

0 Likes

#10

Well the first thing you can see from the debug is that the time is not in msg.payload, but in msg.payload.val, so you would need to provide payload.val in the change string.
Personally I would not do it like that, I would feed it into a moment node, I think that should be capable of doing what you want.
[Edit] That is node-red-contrib-moment

2 Likes

#11

Since your time is in payload.val, try

image

1 Like

#12

Thank you guys! :slight_smile: Wonderful job!

Colin your Idea was great, because by the
other example I had the prob that the seconds
were still there at the end. So thank you very much!!!

0 Likes