Change node not replacing text

I'm sure I am missing something obvious, but why isn't this working? Tried with and without quotes.

image

Output (and input)

image

I'm wondering if it is trying whole text match? I'm sure I have done this before.

It probably isn't a string, but a javascript date, which the debug node is helpfully displaying in a readable form. In a function node put
node.warn(typeof msg.time)
and see what it says.

Why do you need this? I can't imagine a use case.

1 Like

Python does not convert times in the form 'Z' despite it being ISO standard as the fromISO method is the inverse of the toISO method and the toISO method does not generate a Z format just a +00:00 format.

Type Object so looks like you are correct (I think).

That doesn't explain what your use case is. What are you doing with the timestamp after you have modified it?

Sending it to another process that (might) use Python to manipulate the time. If it finds Z, Pyton assumes it is a local time/Date string. Not what I want.

How do I tell Javascript this is a time Object. It seems to helpfully know it isn't a string, but refuses to allow date/time methods on it :frowning:

Do I need to declare a new date object?

[edit]
Doh! a while since I have done Javascript - it is case sensitive.

I think the question you need to ask is how to I convert a javascript Date into a string of the form you want.
You could use toISOString() and then change the Z as you have already tried, or I expect you could use node-red-contrib-moment. Probably several other ways.

I am astonished that Python will not handle an ISO date.

It does handle ISO dates just not ones with Z as a suffix.

[edit]
Unless something has changed recently.

[edit2]
Thanks

msg.time = msg.time.toISOString().replace("Z", "+00:00");

Google suggests that python-dateutil will do it.

Yes I know about that package, but it is not a core package.

I'd rater always export data out of NR that is in a time format that cannot be misinterpreted. I mostly convert to an integer.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.