You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

获取SAP Fiori Launch Pad登录用户日期格式问题求助

获取Fiori Launchpad已登录用户的日期格式解决方案

Hey there! I get that you're trying to pull the logged-in user's custom date format from Fiori Launchpad and ran into issues with the method you tried returning undefined. Let's break this down and fix it together.

Why your initial method didn't work

The sap.ui.getCore().getConfiguration().getFormatSettings().getDatePattern("medium") call retrieves UI5 framework's default date pattern, not the personalized date format the user set in FLP. That's why it returned undefined when the user has a custom format configured—this method doesn't access the user-specific preferences stored in FLP.

The correct way to fetch user's date format

Fiori Launchpad stores user preferences (like date formats) in the UserInfo service. Here's how to access it properly:

  1. First, get the UserInfo service from the FLP container, then fetch the user's date format preference:
// Retrieve the UserInfo service asynchronously
sap.ushell.Container.getServiceAsync("UserInfo").then(function(oUserInfo) {
  // Get the user's personalized date format
  var userDateFormat = oUserInfo.getUser().getPreferences().getDateFormat();
  console.log("User's custom date format:", userDateFormat);
});
  1. If you need to use this format to format dates with UI5's date formatter, you can extend the code like this:
sap.ushell.Container.getServiceAsync("UserInfo").then(function(oUserInfo) {
  var userDatePattern = oUserInfo.getUser().getPreferences().getDateFormat();
  let dateFormatter;

  if (userDatePattern) {
    // Use the user's custom pattern
    dateFormatter = sap.ui.core.format.DateFormat.getDateInstance({
      pattern: userDatePattern
    });
  } else {
    // Fallback to the framework's medium date format if no custom setting exists
    dateFormatter = sap.ui.core.format.DateFormat.getDateInstance({
      style: "medium"
    });
  }

  // Test with today's date
  const today = new Date();
  console.log("Formatted date:", dateFormatter.format(today));
});

Quick note

Make sure this code runs within the Fiori Launchpad environment—the sap.ushell.Container object is only available here, so it won't work in a standalone UI5 app or local test without FLP context.

内容的提问来源于stack exchange,提问作者tarzanbappa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:18:55