标签:
//日期对象原型格式方法
Date.prototype.pattern=function(fmt) {
var o = {
"M+" : this.getMonth()+1, //月份
"d+" : this.getDate(), //日
"h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时
"H+" : this.getHours(), //小时
"m+" : this.getMinutes(), //分
"s+" : this.getSeconds(), //秒
"q+" : Math.floor((this.getMonth()+3)/3), //季度
"S" : this.getMilliseconds() //毫秒
};
var week = {
"0" : "\u65e5",
"1" : "\u4e00",
"2" : "\u4e8c",
"3" : "\u4e09",
"4" : "\u56db",
"5" : "\u4e94",
"6" : "\u516d"
};
if(/(y+)/.test(fmt)){
fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
if(/(E+)/.test(fmt)){
fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "\u661f\u671f" : "\u5468") : "")+week[this.getDay()+""]);
}
for(var k in o){
if(new RegExp("("+ k +")").test(fmt)){
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
}
}
return fmt;
};
//格式化时间函数,此函数为了处理json格式中带date类型数据的
function formatJson(time)
{
var jsonDate=new Date(time);
var result = jsonDate.format("yyyy-MM-dd hh:mm");
return jsonDate;
}
Date.prototype.format = function(format){
var o =
{
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format))
format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
for(var k in o)
if(new RegExp("("+ k +")").test(format))
format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
return format;
}
cyper的java代碼(spring mvc controller):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
@RequestMapping (value = "calendarEvents" ) @ResponseBody public String calendarEvents(){ List<LecturerAgendaVo> agendas = lecturerAgendaService.findAllMatchedAgenda(); StringBuilder sb = new StringBuilder(); sb.append( "[" ); for (LecturerAgendaVo agenda: agendas){ sb.append( "{\"id\":" + agenda.getId()); sb.append( ",\"title\":\"\\n" + agenda.getLecterName()+ "\\n" ); sb.append(agenda.getSchoolName()+ "\\n" ); sb.append(agenda.getStartTime() + "-" + agenda.getEndTime() + "\\n" ); sb.append( "\"" ); sb.append( ",\"start\":\"" + agenda.getLectDate() + " " + agenda.getStartTime() + ":00\"" ); sb.append( ",\"end\":\"" + agenda.getLectDate() + " " + agenda.getEndTime() + ":00\"" ); sb.append( "}," ); } sb.setLength(sb.length()- 1 ); sb.append( "]" ); return sb.toString(); } |
cyper的javascript:
1
2
3
4
5
6
7
8
9
10
11
12
|
$(document).ready( function () { $( ‘#calendar‘ ).fullCalendar({ header: { left: ‘prev,next today‘ , center: ‘title‘ , right: ‘month,basicWeek,basicDay‘ }, editable: false , events: ‘${ctx}/mgr/lect/apply/calendarEvents.json‘ }); }); |
以下為轉載部分:
fullcalendar 的帮助文档 可见地址:http://arshaw.com/fullcalendar/docs/
jQuery日历FullCalendar插件是一个非常不错的日历工具,可用于制作日程表或计划安排
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<pre class = "javascript" name= "code" > $( ‘#calendar‘ ).fullCalendar({ events: { url: ‘<%=request.getContextPath()%>/displayAction.do?method=testJson‘ //你的controller的地址 type: ‘POST‘ , error: function () { alert( ‘there was an error while fetching events!‘ ); }, color: ‘yellow‘ , // 背景色 textColor: ‘black‘ // 文字颜色 } });</pre> <pre></pre> |
java代码
1
2
3
4
5
6
7
8
9
10
11
|
public ModelAndView testJson(HttpServletRequest request, HttpServletResponse response) { String strvalue = "[{\"id\":111,\"title\":\"Event1\",\"start\":\"2012-03-10\",\"url\":\"http:\\/\\/yahoo.com\\/\"},{\"id\":222,\"title\":\"Event2\",\"start\":\"2012-03-20\",\"end\":\"2012-03-22\",\"url\":\"http:\\/\\/yahoo.com\\/\"}]" ; response.setCharacterEncoding( "UTF-8" ); System.out.println( "strvalue=" +strvalue); try { response.getWriter().print(strvalue); } catch (IOException e) { e.printStackTrace(); } return null ; } |
3 events (as a function)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
$( ‘#calendar‘ ).fullCalendar({ events: function (start, end, timezone, callback) { $.ajax({ url: "<%=request.getContextPath()%>/displayAction.do?method=getTitle" , cache: false , success: function (doc) { eval( "var j=" + doc); var events = []; var info = j.eventinfo; for ( var i = 0; i < info.length; i++) { var ev = info[i]; var title = ev.title; var evtstart = new Date(Date.parse(ev.start)); var evtend = new Date(Date.parse(ev.end)); events.push({ title:title, start:evtstart, end:evtend, id:1 }); } callback(events); }, error: function () { alert( ‘sdf‘ ) } }) } }) |
java代码
1
2
3
4
5
6
7
8
9
10
11
|
public ModelAndView getTitle(HttpServletRequest request, HttpServletResponse response) { String strvalue = "{ ‘eventinfo‘:[{day: ‘3/3/2012‘,eventtitle:‘test1‘},{day: ‘3/8/2012‘,eventtitle:‘test2‘} ]} " ; response.setCharacterEncoding( "UTF-8" ); System.out.println( "strvalue=" +strvalue); try { response.getWriter().print(strvalue); } catch (IOException e) { e.printStackTrace(); } return null ; } |
标签:
原文地址:http://www.cnblogs.com/huideng/p/4545493.html