Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
351 views
in Technique[技术] by (71.8m points)

date - How to format "MM/yyyy" pattern to locale-dependent "<month name> / yyyy" in SAPUI5?

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?

Screenshot of SAPUI5 responsive table asking for date UI format

Snippet from my XML view:

<cells>
  <Text text="{Period}" />
  <!-- ... -->
<cells>

Period is an OData V2 entity property and its EDM type is String.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...