export class TimeUtils {

    /**
     * 月/日 小时:分钟
     * @param value 
     */
    static  formatData(value: number): string {
        var str: string = "";
        var date: Date = new Date(value * 1000);
        str = this.getTwo(date.getMonth() + 1) + "/" + this.getTwo(date.getDate()) + " " + this.getTwo(date.getHours()) + ":" + this.getTwo(date.getMinutes());
        return str;
    }

    /**
     * 月/日
     * @param value 
     */
    static  formatData1(value: number): string {
        var str: string = "";
        var date: Date = new Date(value * 1000);
        str = (date.getMonth() + 1) + "月" + date.getDate() + "日";
        return str;
    }

    /**
     * 年月日
     * @param value 
     */
    static  formatYearMonthDate(value: number): string {
        var str: string = "";
        var date: Date = new Date(value * 1000);
        str = date.getFullYear() + "." + (date.getMonth() + 1) + "." + date.getDate();
        return str;
    }

    /**
     * 年-月-日
     * @param value 
     */
    static  formatYearMonthDate1(value: number): string {
        var str: string = "";
        var date: Date = new Date(value * 1000);
        var month: string = (date.getMonth() + 1) >= 10 ? (date.getMonth() + 1).toString() : "0" + (date.getMonth() + 1);
        var dates: string = date.getDate() >= 10 ? date.getDate().toString() : "0" + date.getDate();
        str = date.getFullYear() + "-" + month + "-" + dates;
        return str;
    }


    static  LXandJXTimeType(value: number): string {
        var str: string = "";
        if (value < 0) {
            str = "0秒";
        } else if (value < 60) {
            str = Math.floor(value) + "秒";
        } else if (value < 60 * 60) {
            str = Math.floor(value / 60) + "分钟";
        } else {
            var hour: number;
            hour = Math.floor(value / 60 / 60);
            str = hour + "小时";
            str += Math.floor((value - hour * 60 * 60) / 60) + "分钟";
        }
        return str;
    }

    /**
     * 格式化时间
     * @param time 秒
     * @return 返回24:59:59
     */
    static  formatTime(time: number): string {
        var str: string = "";
        var hours: number = Math.floor(time / 3600);
        if( hours > 0 )
        {
            str += hours >= 10 ? (hours + ":") : ("0" + hours + ":");
        }
        var minutes: number = Math.floor((time % 3600) / 60);
        str += minutes >= 10 ? (minutes + ":") : ("0" + minutes + ":");
        var second: number = Math.floor(time % 60);
        str += second >= 10 ? (second + "") : ("0" + second);
        return str;
    }

    /**
     * 格式化时间
     * @param time 秒
     * @return 返回24小时59分59秒 
     */
    static  formatTime1(time: number): string {
        var str: string = "";
        var hours: number = Math.floor(time / 3600);
        if( hours > 0 )
        {
            str += hours + "小时";
        }
        var minutes: number = Math.floor((time % 3600) / 60);
        str += minutes + "分钟";
        var second: number = Math.floor(time % 60);
        str += second + "秒";
        return str;
    }

    /**
     * 格式化时间
     * @param time 秒
     * @return 返回1小时24分10秒
     */
    static  formatTime5(time: number): string {
        var str: string = "";
        var hours: number = Math.floor(time / 3600);
        if( hours > 0 )
        {
            str += hours + "小时";
        }
        var minutes: number = Math.floor((time % 3600) / 60);
        if(minutes>0)
        {
            str += minutes + "分";
        }
        var second: number = Math.floor(time % 60);
        str += second + "秒";
        return str;
    }

    /**
     * 格式化时间
     * @param time 秒
     * @return 返回1天24小时59分59秒
     */
    static  formatTime2(time: number): string {
        var str: string = "";
        var day: number = Math.floor(time / 86400);
        if(day>0){
            str += day + "天";
        }
        var hours: number = Math.floor(time / 3600);
        if(hours>0){
            str += hours + "小时";
        }
        var minutes: number = Math.floor((time % 3600) / 60);
        if(minutes>0){
            str += minutes + "分钟";
        }
        var second: number = Math.ceil(time % 60);
        str += second + "秒";
        return str;
    }

    /**
     * 格式化时间
     * @param time 秒
     * @return 返回1天24小时（ 只保留两个 ）
     */
    static  formatTime6(time: number): string {
        var str: string = "";
        var index:number = 0;
        var day: number = Math.floor(time / 86400);
        if (day>0){
            str += day + "天";
            index++;
        }
        var hours: number = Math.floor((time % 86400) / 3600);
        if (hours>0){
            str += hours + "小时";
            index++;
        }
        if (index < 2)
        {
            var minutes: number = Math.floor((time % 3600) / 60);
            if(minutes>0){
                str += minutes + "分";
                index++;
            }
        }
        if (index < 2)
        {
            var second: number = Math.ceil(time % 60);
            str += second + "秒";
        }
        return str;
    }

    /**
 * 格式化时间
 * @param time 秒
 * @return 返回1天24小时59分
 */
static  formatTime3(time: number): string {
        var str: string = "";
        var day: number = Math.floor(time / 86400);
        str += day + "天";
        var hours: number = Math.floor(time % 86400 / 3600);
        str += hours + "小时";

        var minutes: number = Math.floor((time % 86400 % 3600) / 60);
        str += minutes + "分";

        return str;
    }

    /**
* 格式化时间
* @param time 秒
* @return 返回1天24小时59分
*/
static  formatTime4(time: number): string {
        var str: string = "";
        if (time > 86400) {
            var day: number = Math.floor(time / 86400);
            str += day + "天";
        }
        if (time > 3600) {
            var hours: number = Math.floor(time % 86400 / 3600);
            str += hours + "小时";
        }
        if (time > 60) {
            var minutes: number = Math.floor((time % 86400 % 3600) / 60);
            str += minutes + "分钟";
        }

        return str;
    }

        /**
* 格式化时间
* @param time 秒
* @return 返回1天24小时59分
*/
static  formatTime4Arr(time: number): Array<string> {
        var arrTime:Array<string> = [];
        var str: string = "";
        // if (time >= 86400) {
        //     var day: number = Math.floor(time / 86400);
        //     arrTime.unshift(String(day));
        // }
        if (time >= 3600) {
            var hours: number = Math.floor(time % 86400 / 3600);
            arrTime.unshift(String(hours));
        }
        if (time >= 60) {
            var minutes: number = Math.floor((time % 86400 % 3600) / 60);
            arrTime.unshift(String(minutes));
        }

        return arrTime;
    }


    static  getTwo(value: any): string {
        var str: string = String(value);
        if (str.length < 2) {
            str = "0" + str;
        }
        return str;
    }

    /**
     * 日期转时间戳
     * @param str 2018-1-1 
     */
    static  datetoTime(str: string): number {
        return Date.parse(str) / 1000;
    }
}