从后端开始,日期格式与上面类似,我想使用格式化程序将日期格式化为实际日期。我的datepicker
中有一个detailpage
,而datepicker
想要一个真实的日期来显示。
所以我尝试了一下,但无法正常工作。所以也许有人可以帮助我或指导如何做?我知道我可以在后端格式化日期,但我需要像上面那样将其作为字符串。
答案 0 :(得分:1)
如果您在此处使用sap.m.DatePicker
,例如:
<DatePicker
id="DP2"
value="2014-03-26" valueFormat="yyyy-MM-dd" displayFormat="long"
change="handleChange"
class="sapUiSmallMarginBottom"/>
有valueFormat
和displayFormat
属性可以根据需要调整日期格式。
valueFormat
是用户单击日期时想要的日期格式,您可以在oEvent
中进行抓取。
displayFormat
是您要显示的日期格式。
答案 1 :(得分:0)
嗨,您可以使用下面的js代码从收到的字符串中创建日期
getDate:function(value){
//value is your string from backend "20120515"
if(value){
var dateString = value;
var year = dateString.substring(0,4);
var month = dateString.substring(4,6);
var day = dateString.substring(6,8);
var date = new Date(year, month-1, day);
return date; // Keep in mind the date returned will only be correct if the string is passed in above format
}
}
您可以在formatter.js文件中使用上述功能,并可以在datepicker中使用以下功能
<DatePicker value="{path:'modelDateProperty', formatter:'.formatter.getDate', }" />
我希望这对您有帮助