Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SAPUI5-Dateformat-如何使用Dateformat格式化日期_Date_Format_Sapui5 - Fatal编程技术网

SAPUI5-Dateformat-如何使用Dateformat格式化日期

SAPUI5-Dateformat-如何使用Dateformat格式化日期,date,format,sapui5,Date,Format,Sapui5,假设我有一个日期作为字符串,格式为yyyy-MM-dd,我希望它的格式为样式:“short”。 我只想使用Dateformat 我用它来了解如何使用DateFormat 但我看不出,我的代码有什么问题: date: function(sdate) { var regex = "[0-9]{4}-[0-9]{2}-[0-9]{2}"; if (!sdate.match(regex)) return "no valid date given"; jQuery.sap.re

假设我有一个日期作为字符串,格式为
yyyy-MM-dd
,我希望它的格式为
样式:“short”
。 我只想使用
Dateformat

我用它来了解如何使用
DateFormat

但我看不出,我的代码有什么问题:

date: function(sdate) {
   var regex = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
   if (!sdate.match(regex))
    return "no valid date given";

   jQuery.sap.require("sap.ui.core.format.DateFormat");
   var oDateFormat = sap.ui.core.format.DateFormat.getInstance({pattern: "yyyy-MM-dd", style: "short"});
   return oDateFormat.format(sdate); //date should be returned here in "short"-style
}
控制台告诉我
TypeError:j.getTime不是函数
。 此外,WebIDE似乎不知道函数
Datetime.format()


您能帮忙吗?

您可能会重新阅读链接中的文档:要将字符串转换为JS日期,您必须使用
DateFormat.parse
方法。

您可能会重新阅读链接中的文档:要将字符串转换为JS日期,您必须使用
DateFormat.parse
方法。

这是否回答了您的问题?这回答了你的问题吗?