[Solved] How to format “MM/yyyy” pattern to locale-dependent ” / yyyy” in SAPUI5?


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.DateTime should be considered.

0

solved How to format “MM/yyyy” pattern to locale-dependent “ / yyyy” in SAPUI5?