I get dates from backend as data format "12/2019" and would like to convert in the format "Dez / 2019" ("Dez" in German, "Dec" in English). Has anyone an idea?
Snippet from my XML view:
<cells>
<Text text="{Period}" />
<!-- ... -->
<cells>
Period
is an OData V2 entity property and its EDM type is String.
Try with:
<Text text="{
path: 'Period',
type: 'sap.ui.model.type.Date',
formatOptions: {
pattern: 'MMM / yyyy',
source: {
pattern: 'MM/yyyy'
}
}
}" />
Here is a working demo (Click on Run code snippet ):
sap.ui.getCore().attachInit(() => sap.ui.require([ "sap/ui/core/Fragment", ], Fragment => Fragment.load({ definition: `<Text xmlns="sap.m" text="{ value: '12/2019', type: 'sap.ui.model.type.Date', formatOptions: { pattern: 'MMM / yyyy', source: { pattern: 'MM/yyyy' } } }" />` }).then(control => control.placeAt("content"))));
<script id="sap-ui-bootstrap" src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" data-sap-ui-libs="sap.ui.core,sap.m" data-sap-ui-theme="sap_fiori_3" data-sap-ui-async="true" data-sap-ui-compatversion="edge" data-sap-ui-xx-waitfortheme="init" ></script><body id="content" class="sapUiBody"></body>
Since the EDM Type of Period
is String, simply using sap.ui.model.type.Date
should be sufficient in this case. If the Type is however Edm.DateTime
, which is usually used to represent date values in OData V2, then the type sap.ui.model .odata .type.Date Time
should be considered.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.