| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- // Learn cc.Class:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
- // Learn Attribute:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
- // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
- cc.Class({
- extends: cc.Component,
- properties: {
- // foo: {
- // // ATTRIBUTES:
- // default: null, // The default value will be used only when the component attaching
- // // to a node for the first time
- // type: cc.SpriteFrame, // optional, default is typeof default
- // serializable: true, // optional, default is true
- // },
- // bar: {
- // get () {
- // return this._bar;
- // },
- // set (value) {
- // this._bar = value;
- // }
- // },
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad: function () {
- this.type = 0;
- this.startTime();
- },
- startTime: function () {
- var myData = new Date();
- this.mytime = myData.getTime();
- },
- update: function (dt) {
- var testDate = new Date();
- // testDate.getYear(); //获取当前年份(2位)
- // testDate.getFullYear(); //获取完整的年份(4位,1970-????)
- // testDate.getMonth(); //获取当前月份(0-11,0代表1月)
- // testDate.getDate(); //获取当前日(1-31)
- // testDate.getDay(); //获取当前星期X(0-6,0代表星期天)
- var mytime = testDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
- // testDate.getHours(); //获取当前小时数(0-23)
- // testDate.getMinutes(); //获取当前分钟数(0-59)
- // testDate.getSeconds(); //获取当前秒数(0-59)
- // testDate.getMilliseconds(); //获取当前毫秒数(0-999)
- // testDate.toLocaleDateString(); //获取当前日期
- // var mytime=testDate.toLocaleTimeString(); //获取当前时间
- // testDate.toLocaleString( ); //获取日期与时间
- cc.log("开启计时器之后的毫秒", mytime - this.mytime);
- //直接调用公共JS里面的时间类处理的办法
- cc.log("格式化之后的计时器", this.dateFttM("ss:S",mytime - this.mytime));
- },
- dateFtt: function (fmt, date) { //author: meizz
- var o = {
- "M+": date.getMonth() + 1, //月份
- "d+": date.getDate(), //日
- "h+": date.getHours(), //小时
- "m+": date.getMinutes(), //分
- "s+": date.getSeconds(), //秒
- "q+": Math.floor((date.getMonth() + 3) / 3), //季度
- "S": date.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt))
- fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
- 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;
- },
- dateFttM: function (fmt, milliseconds) { //author: meizz
- var date = new Date(milliseconds);
- cc.log("这是什么啊", date);
- var o = {
- "M+": date.getMonth() + 1, //月份
- "d+": date.getDate(), //日
- "h+": date.getHours(), //小时
- "m+": date.getMinutes(), //分
- "s+": date.getSeconds(), //秒
- "q+": Math.floor((date.getMonth() + 3) / 3), //季度
- "S": date.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt))
- fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
- 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;
- }
- });
|