on 10-12-2016 10:16 PM
Hello,
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.
Michael
I think you can use below code in your xml view, no need to use formatter function and this will handle timezone diff and all.
<DatePicker value="{path: 'fromDate', type: 'sap.ui.model.type.Date', formatOptions: {pattern: 'yyyy/MM/dd', strictParsing: true , UTC: true}}">
</DatePicker>
Hope will be helpful.
Regards,
Akhilesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is there a way to set the UTC value dynamically? Like taking it from a model or setting it programatically from the controller?
In your XML view you should be able to use the following in the datepicker tag
displayFormat="YYYY/MM/DD" valueFormat="YYYY/MM/DD"
That should work. Otherwise try using a formatter.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can also check additionaly information how to use 'sap.ui.core.format.DateFormat' use https://help.sap.com/saphelp_uiaddon10/helpdata/en/91/f2eba36f4d1014b6dd926db0e91070/content.htm
User | Count |
---|---|
86 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.