Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Hi all,
I need to format current date time on ThingWorx expression widget, but javascript functions do not work without libraries (i.e. dateFormat(newDate(), "dd-MM-YYYY HH:mm")). How can I format datetime with native functions?
Thanks,
Elisabetta
You can use Javascript Standard DateTime Format functions, something like:
new Date().toLocaleString()
Hello,
To expand on Carles' reply:
Carles' suggestion + Option (2) are the best variants, because they take into account user's locale settings.
Regards,
Constantine
Yup, but I would never use Option 3, as it will be formated at Server TimeZone not at user's Timezone ;)
Agree, (3) is a bad idea, it would be the last thing I recommend.
Having said that, there are some exceptions:
As a rule of thumb formatting date/time on the server side is almost always a bad idea. But if (and only if) you have a very clear idea about how it works (like your famous extension), then you can break the rules sometimes :)
As you said, if you have to format DateTime on ServerSide, which actually we are doing it (and it's not that strange on the use cases you pointed out - email, notifications,...-) you need an extension in order to format it correctly (my one :P) of course knowing before the right Timezone for the User or for the Thing...