jquery时间戳怎么转成日期格式

jquery时间戳怎么转成日期格式,第1张

这个不能直接转换。只能自己编写。

下面是简单的例子。并有基本注释:

(function($) {

    $extend({

        myTime: {

            /

              当前时间

              @return <int>        unix时间戳(秒)  

             /

            CurTime: function(){

                return Dateparse(new Date())/1000;

            },

            /              

              日期 转换为 Unix时间戳

              @param <string> 2014-01-01 20:20:20  日期格式              

              @return <int>        unix时间戳(秒)              

             /

            DateToUnix: function(string) {

                var f = stringsplit(' ', 2);

                var d = (f[0]  f[0] : '')split('-', 3);

                var t = (f[1]  f[1] : '')split(':', 3);

                return (new Date(

                        parseInt(d[0], 10) || null,

                        (parseInt(d[1], 10) || 1) - 1,

                        parseInt(d[2], 10) || null,

                        parseInt(t[0], 10) || null,

                        parseInt(t[1], 10) || null,

                        parseInt(t[2], 10) || null

                        ))getTime() / 1000;

            },

            /              

              时间戳转换日期              

              @param <int> unixTime    待时间戳(秒)              

              @param <bool> isFull    返回完整时间(Y-m-d 或者 Y-m-d H:i:s)              

              @param <int>  timeZone   时区              

             /

            UnixToDate: function(unixTime, isFull, timeZone) {

                if (typeof (timeZone) == 'number')

                {

                    unixTime = parseInt(unixTime) + parseInt(timeZone)  60  60;

                }

                var time = new Date(unixTime  1000);

                var ymdhis = "";

                ymdhis += timegetUTCFullYear() + "-";

                ymdhis += (timegetUTCMonth()+1) + "-";

                ymdhis += timegetUTCDate();

                if (isFull === true)

                {

                    ymdhis += " " + timegetUTCHours() + ":";

                    ymdhis += timegetUTCMinutes() + ":";

                    ymdhis += timegetUTCSeconds();

                }

                return ymdhis;

            }

        }

    });

})(jQuery);

function getLastMaxDay(this_date){

var mon=(0==$trim(this_date)substring(4,5))$trim(this_date)substring(5,6):$trim(this_date)substring(4,6);

var day="";

var year_mon="";

if(mon>10){

mon=mon-2;

}else if(mon==10){

mon=mon-2;

}else{

mon=mon-2;

}

var year=$trim(this_date)substring(0,4);

var dt = new Date(year,mon,1);

//var dt = new Date();

dtsetDate(1);

dtsetMonth(dtgetMonth()+1);

cdt = new Date(dtgetTime()-1000606024);

return cdtgetDate();

}

//去除最后的逗号

function toIdsForIn(id){

var arr=(id+"")split(',');

return arrjoin("','");

}

>

您好,这样:

//| 日期有效性验证

//| 格式为:YYYY-MM-DD或YYYY/MM/DD

function IsValidDate(DateStr){

var sDate=DateStrreplace(/(^\s+|\s+$)/g,'');//去两边空格;

if(sDate==''){

return true;

}

//如果格式满足YYYY-(/)MM-(/)DD或YYYY-(/)M-(/)DD或YYYY-(/)M-(/)D或YYYY-(/)MM-(/)D就替换为''

//数据库中,合法日期可以是:YYYY-MM/DD(2003-3/21),数据库会自动转换为YYYY-MM-DD格式

var s=sDatereplace(/[\d]{ 4,4 }[\-/]{1}[\d]{1,2}[\-/]{1}[\d]{1,2}/g,'');

if(s==''){//说明格式满足YYYY-MM-DD或YYYY-M-DD或YYYY-M-D或YYYY-MM-D

var t=new Date(sDatereplace(/\-/g,'/'));

var ar=sDatesplit(/[-/:]/);

if(ar[0]!=tgetYear()||ar[1]!=tgetMonth()+1||ar[2]!=tgetDate()){//alert('错误的日期格式!格式为:YYYY-MM-DD或YYYY/MM/DD。注意闰年。');

return false;

}

}else{//alert('错误的日期格式!格式为:YYYY-MM-DD或YYYY/MM/DD。注意闰年。');

return false;

}

return true;

}

//转化为毫秒数比价大小就行了

var d_1 = "2014-11-22 11:12:13";

var d_2 = "2014-11-04 11:12:16";

var e_1 = new Date(d_1)getTime();

var e_2 = new Date(d_2)getTime();

//比较e_1和e_2的大小就行了

以上就是关于jquery时间戳怎么转成日期格式全部的内容,包括:jquery时间戳怎么转成日期格式、Jquery怎么得到一个月的所有天数 数据格式为1 2 3 4 5 到月底的所有数字 求高手解答。。。、求 jquery 日期校验 代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9480707.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存