1、Cognos 设置日期默认时间实现步骤:首先在页面添加 1 个日期提示控件,如下图:设置日期控件为编辑框:修改日期控件名称为:PDate添加 html 控件,Html 控件的内容如下:HTML:/date prompt 默认为当日/昨日function subtractDay ()var dtToday = new Date();var dtYesterday = new Date( dtToday - 86400000 );var strYesterday = dtYesterday.getUTCFullYear(), dtYesterday.getMonth()+1, dtYesterda
2、y.getDate().join(“-“);return strYesterday;pickerControlPDate.setValue( subtractDay() );/PDate 为 date prompt 组件名称(日期名称要与其一致)注意事项:这里的数字是一天的,如果要退前多少天就多少天*这个数字,如 7 天就是 7*86400000。完成效果:设置本周第一天:html 控件内容:/本周第一天function showWeekFirstDay() var Nowdate=new Date(); var WeekFirstDay=new Date(Nowdate-(Nowdate.g
3、etDay()-1)*86400000); var strWeekFirstDay = WeekFirstDay.getUTCFullYear(), WeekFirstDay.getMonth()+1, WeekFirstDay.getDate().join(“-“); return strWeekFirstDay; pickerControlPDate.setValue( showWeekFirstDay() );完成效果:因为 28 号本来就是星期一,所以显示的当天的。设置本月第一天:html 控件内容:/本月第一天function ShowMonthLastDay() var Nowda
4、te=new Date(); var MonthNextFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth(),2); var MonthLastDay=new Date(MonthNextFirstDay-86400000); var strMonthLastDay = MonthLastDay.getUTCFullYear(), MonthLastDay.getMonth()+1, MonthLastDay.getDate().join(“-“); return strMonthLastDay;pickerControlPDate.se
5、tValue( ShowMonthLastDay() );完成效果:设置本月最后一天:html 控件内容:/本月第一天function ShowMonthLastDay() var Nowdate=new Date(); var MonthNextFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth()+1,1); var MonthLastDay=new Date(MonthNextFirstDay-86400000); var strMonthLastDay = MonthLastDay.getUTCFullYear(), MonthLastDay.getMonth()+1, MonthLastDay.getDate().join(“-“); return strMonthLastDay;pickerControlPDate.setValue( ShowMonthLastDay() );完成效果: