Time stamp in template

Using a HTTP output node and I would like a current timestamp to be a part of the posted json bodytemplate.
Isn’t there a variable for that?


In your body:

   time: {{time}}

That’s it :slight_smile:

can I format that as moment.js ?
I need to get rid of the 3 decimals of milliseconds.

So, there are template helpers that you can use all throughout Losant. It’s really helpful if you need to format data, and some other cool things. I really recommend reading through all the different helpers to see all that you can do:

There is one you can use in particular for formatting dates. And fun fact, it uses moment behind the scenes :slight_smile:

So I was able to use the {{currentDateTime formatStr}} helper, and that works great.

But if I want to convert a combined string containing a date plus another containing a time, to a valid time stamp and format that, is a function node my only option or can that be done directly in the http nodes body template ?

Hi Lars,

Just to clarify, are you asking how to convert two variables (date and time) into one, or how to convert one combined date and time variable into a timestamp?


It’s really both, but I guess the main question is if I need to use a function node for that or can it be done in the http nodes body template

Hi Lars,

To combine a date and time into one attribute, you would need to use a Function Node. You can then format the combined date and time into a timestamp with the {{formatDate}} helper.