bookCommon.js 1.62 KB
module.exports ={
    //时间戳转化日期
    changedate:function(timestamp){
        var date = new Date(timestamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
        var Y= date.getFullYear();
        var M =date.getMonth()+1;
        var D =date.getDate();
        var h = date.getHours();
        var m = date.getMinutes();
        var s = date.getSeconds();
        return {year:Y,month:M,day:D,hour:h,minute:m,second:s};

    },
    //获取星期
    getweek:function (index) {
        var week=['周日','周一','周二','周三','周四','周五','周六'];
        return week[index]
    },
    //判断是否是整数
    isInteger:function (obj) {
        return obj%1 === 0
    },
    //时间转化时间戳
    gettimestamp:function(stringTime){
        var date = new Date(stringTime.replace(/-/g, '/'));
        var timestamp2=Date.parse(date)/1000;
        return timestamp2
    },
    //日期转换   8月8日----08-08
    get_date:function(thiadate){
        var thismoth=thiadate.split('月')[0];
        var thisday=thiadate.split('月')[1].slice(0,-1);
        var timedate=(parseInt(thismoth)<10 ? '0'+thismoth : thismoth)+'-'+(parseInt(thisday)<10 ? '0'+thisday : thisday);
        return timedate;
    },
    //日期转换   08-08----8月8日
    getdate_num:function(thisdate){
        var thismonth=thisdate.split('-')[0][0]=='0' ? thisdate.split('-')[0][1] : thisdate.split('-')[0];
        var thisday=thisdate.split('-')[1][0]=='0' ? thisdate.split('-')[1][1] : thisdate.split('-')[1];
        console.log()
        var timedate=thismonth+'月'+thisday+'日';
        return timedate;
    }
}