Skip to Content
Former Member
Oct 12, 2016 at 09:16 PM

How to get UTC date from bound datepicker and format it

12959 Views Last edit Oct 12, 2016 at 08:16 PM 2 rev


I am developing a Fiori app which uses a date picker, and I am having troubles getting the correct date to display and format that date. The desired format is YYYY/MM/DD.

*displayFormat property of date picker only works on newly selected dates from the date picker, not bound values coming from the backend*

The date saved in the backend is "Aug 1 2016". When it reaches my formatting function, it is "Sun Jul 31 2016 18:00:00 GMT-0600 (Mountain Daylight Time)", I understand it is 6 hours behind the actual date due to timezone offset. I can use date.toUTCString() to get the proper date, however I want to avoid parsing a string to format it the way I want. I thought that using .getUTCMonth() and .getUTCDate() and other getUTC functions would allow me to work with the same date and format it the way I want, however the month returned in getUTCMonth() is different than the month in toUTCString(), and I don't know why!

See screenshot of my debugger below for visual explanation:

The desired date should be "2016/8/1" in this case, which is correct in toUTCString, but when trying to format it using UTC methods, I get a different date, and non UTC methods return an even "more wrong" date.

Thank you for reading this, any information you can provide is greatly appreciated.



dateformat.png (25.1 kB)