function TimeSubNormal(endtime, starttime) {
var end = new Date(endtime).getTime();
var start;
if (!starttime) {
start = new Date().getTime();
}
else {
start = new Date(starttime).getTime();
}
if (start > end) {
return -1;
}
else {
var alltime = end - start;
var seconds = alltime / 1000;
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
var CDay = days;
var CHour = hours % 24;
var CMinute = minutes % 60;
var CSecond = Math.floor(seconds % 60);
var str = "";
if (CDay > 0) {
str += CDay + "天";
}
if (CHour > 0) {
str += CHour + "小时";
}
if (CMinute > 0) {
str += CMinute + "分钟";
}
if (CSecond > 0) {
str += CSecond + "秒";
}
return str;
}
};
exports.GetTime = GetTime;
exports.GetYear = GetYear;
exports.GetMonth = GetMonth;
exports.GetDay = GetDay;
exports.GetHours = GetHours;
exports.GetMinute = GetMinute;
exports.GetSecond = GetSecond;
exports.TimeSubMillisecond = TimeSubMillisecond;
exports.TimeSubNormal = TimeSubNormal;
})
调用方法:
复制代码 代码如下:
define(function (require, exports, module) {
var $ = require('./js/jquery');
var a=require('./js/time');
alert(a.GetTime(3));
});
三、把jquery 插件的封装成seajs模块
下面是把jquery的一个插件封装成模块的例子
复制代码 代码如下: