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
方法。这是否回答了您的问题?这回答了你的问题吗?