zoukankan      html  css  js  c++  java
  • jquery格式化时间戳 2011-01-01

    /*              
     * 时间戳转换日期              
     * @param  <int>  unixTime    待时间戳(秒)              
     * @param  <bool> isFull    返回完整时间(Y-m-d 或者 Y-m-d H:i:s)              
     * @param  <bool> isCheckTime    true返回2015-07-05  false:2015-7-5           
     * @param  <int>  timeZone   时区
     */
    function formatDate(unixTime, isFull=true, timeZone, isCheckTime=true) {
        if (typeof (timeZone) == 'number') {
            unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
        }
        var time = new Date(unixTime * 1000);
        var ymdhis = "";
     
        if (isCheckTime === true) {
            ymdhis += time.getUTCFullYear() + "-";
            ymdhis += formatDateCheckTime((time.getUTCMonth() + 1)) + "-";
            ymdhis += formatDateCheckTime(time.getUTCDate());
            if (isFull === true) {
                ymdhis += " " + formatDateCheckTime(time.getUTCHours()) + ":";
                ymdhis += formatDateCheckTime(time.getUTCMinutes()) + ":";
                ymdhis += formatDateCheckTime(time.getUTCSeconds());
     
            }
        } else {
            ymdhis += time.getUTCFullYear() + "-";
            ymdhis += (time.getUTCMonth() + 1) + "-";
            ymdhis += time.getUTCDate();
            if (isFull === true) {
                ymdhis += " " + time.getUTCHours() + ":";
                ymdhis += time.getUTCMinutes() + ":";
                ymdhis += time.getUTCSeconds();
            }
        }
     
        return ymdhis;
    }
     
    /*              
     * 时间戳转换日期之检测对象是否小于10    
     */
    function formatDateCheckTime(i) {
        if (i < 10)
        { i = "0" + i }
        return i
    }
  • 相关阅读:
    eclips断点调试
    单位换算
    信息论与编码复习
    嵌入式学习笔记
    DAVINCI项目日志
    英语考试方法
    虚拟机安装Ubuntu的上网设置(有线网络和无线网络)
    重装系统必须备份的几种数据
    linux笔记
    word应用技巧
  • 原文地址:https://www.cnblogs.com/meibao/p/4936321.html
Copyright © 2011-2022 走看看