/*
 * @FilePath: \wang-vue-worke:\demo\daping\src\hook\nowTime.ts
 * @Author: 王路平
 * @文件版本: V1.0.0
 * @Date: 2023-02-08 13:15:38
 * @Description: 
 * 
 * 版权信息         : 2023 by ${再登软件}, All Rights Reserved.
 */
import { getStoredLanguage } from '@/utils/languageStorage';
import {onMounted, onUnmounted, reactive, ref} from 'vue'
export default function( ){
    let timeHtml =ref('')
    let flag=ref(true)
    //获取系统时间
    function gettime(){
        var time = new Date();
 
        var year = time.getFullYear();
        // 1月到12月(0-11)
        var month = time.getMonth()+1;
        var dates = time.getDate();
 
        // 周日-周六(0-6) 刚好对应数字下标
        var day = time.getDay();
        if (getStoredLanguage() == 'English/USD') {
            var arr = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
    } else {
            var arr = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
    }
        var hours:any = time.getHours();
        var minutes:any = time.getMinutes();
        var seconds:any = time.getSeconds();
        // 小于10分钟前面补零
        if (hours < 10) hours = "0" + hours;
        if (minutes < 10) minutes = "0" + minutes;
        if (seconds < 10) seconds = "0" + seconds;
 
        return year + "-" + month + "-" + dates + " "+hours+':'+minutes+':'+seconds+' '+arr[day];
}
    onMounted(() => {
        let time =setInterval(() => {
            if(flag.value){
                timeHtml.value = gettime()   
            }else{
                clearInterval(time)
            }
          }, 1000)
         
          
    })
    onUnmounted(() => {
        flag.value = false
    })
    return {timeHtml}
}