且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SAP UI5应用里类型为Edm.DateTime的日期控件设计原理

更新时间:2022-09-03 21:23:09

Recently I was struggled with a customer incident and finally I realized that I didn’t understand the Edm.DateTime quite clearly. So I spend some time to do research on it to fix my knowledge gap. I list my learning here in case any other guy needs it as well.

For my study, I use this field in my application for example.

SAP UI5应用里类型为Edm.DateTime的日期控件设计原理SAP UI5应用里类型为Edm.DateTime的日期控件设计原理SAP UI5应用里类型为Edm.DateTime的日期控件设计原理SAP UI5应用里类型为Edm.DateTime的日期控件设计原理Why is there difference between them?

And when I type “alert(new Date(1443830400000));” in chrome console, I get this popuSAP UI5应用里类型为Edm.DateTime的日期控件设计原理Actually it ( 2015-10-03 08:00:00 GMT +0800 ) points to exactly the same time as 2015-10-03 00:00:00 UTC.


So how could the date with format /Date(1443830400000)/ be consumed in my application?


It makes sense to start debugging via the framework handler when the response of odata request ( Opportunity re-read after closing date is changed ) is successfully returned:

SAP UI5应用里类型为Edm.DateTime的日期控件设计原理The aim is to figure out how framework parses this /Date(1443744000000)/.

Then I reached the place:


(1) there is a regular expression which extracts the number 1443744000000 from the input string.


(2) a local time is returned by new Date(), with the number parsed by previous step passed in. The local time is returned based on current Time zone configured in my laptop.

SAP UI5应用里类型为Edm.DateTime的日期控件设计原理Then the local time returned by framework will be passed into my formatter so now I could do any formatting based on customer requirement:


[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-V7xzygvx-1596956679633)(https://upload-images.jianshu.io/upload_images/2085791-bfe738ad92f3cb66.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]