Is there a simple way to return moment’s fromNow function?
https://momentjs.com/docs/#/displaying/fromnow/
I can’t see it in the UI, and I’ve so far tried and failed to get a custom formatter that works!
Thanks!
Is there a simple way to return moment’s fromNow function?
https://momentjs.com/docs/#/displaying/fromnow/
I can’t see it in the UI, and I’ve so far tried and failed to get a custom formatter that works!
Thanks!
Here is one way…including a (optional) customization of what is returned.
dmx.Formatter('string', 'timeFromNow', function(val, format) {
moment.updateLocale('en', {
relativeTime : {
future: "in %s",
past: "%s ago",
s : '%ds',
ss : '%ds',
m: "1m",
mm: "%dm",
h: "1h",
hh: "%dh",
d: "1d",
dd: "%dd",
w: "1w",
ww: "%dw",
M: "1M",
MM: "%dM",
y: "1y",
yy: "%dy"
}
});
return moment.utc(val).fromNow(true);
});
and then call that formatter:
{{created.timeFromNow()}}
where created is a datetime value.
Works a treat, thanks very much!!
Hi, could you tell me where I can enter/save the dmx.formatter for relative time? I’m a bit lost.
I would like to use 1m, 1w, 1mo and so on.
& I presume I call it like this?
I see now it’s inserted in javascript file. Thanks @mebeingken
If I want to use ‘mo’ for month instead of M, would this work?