资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

时间转换jquery,时间转换为数字

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

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

专注于为中小企业提供成都网站建设、做网站服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业义马免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

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

(function($) {

$.extend({

myTime: {

/**

* 当前时间戳

* @return int        unix时间戳(秒)  

*/

CurTime: function(){

return Date.parse(new Date())/1000;

},

/**              

* 日期 转换为 Unix时间戳

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

* @return int        unix时间戳(秒)              

*/

DateToUnix: function(string) {

var f = string.split(' ', 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 += time.getUTCFullYear() + "-";

ymdhis += (time.getUTCMonth()+1) + "-";

ymdhis += time.getUTCDate();

if (isFull === true)

{

ymdhis += " " + time.getUTCHours() + ":";

ymdhis += time.getUTCMinutes() + ":";

ymdhis += time.getUTCSeconds();

}

return ymdhis;

}

}

});

})(jQuery);

jquery里,怎么格式化时间

jquery里格式化时间采用日期format函数:

1、需要格式化的时间html代码:

span class="date"06-Aug-2012/span

span class="date"2012/06/Aug/span

span class="date"Monday, August 06, 2012/span

2、formt日期的核心js代码:

$(document).ready(function () {

$('span.date').each(function() {

var dateFormat = $(this).text()

var dateFormat = $.datepicker.formatDate('MM dd, yy', new Date(dateFormat));

//alert(dateFormat);

$(this).html(dateFormat + "br");

});

});

3、运行结果:

06-Aug-2012 2012/06/Aug Monday, August 06, 2012

javascript 或jquery时间类型转换

在javascript中直接输出Date得到的结果是这样的:

function date(){

var date = new Date();

alert(date);

}

结果是:Mon Jun 15 15:30:46 UTC+0800 2009

得到new Date()型中各个时间级别(年、月、日、时、分、秒)的数:

function date(){

var date = new Date();

var year = date.getFullYear();

var month = date.getMonth()+1; //js从0开始取

var date1 = date.getDate();

var hour = date.getHours();

var minutes = date.getMinutes();

var second = date.getSeconds();

alert(date+" | "+year+"年"+month+"月"+date1+"日"+hour+"时"+minutes +"分"+second+"秒" );

}

得到的结果就是:Mon Jun 15 15:44:50 UTC+0800 2009 | 2009年6月15日15时44分50秒


分享标题:时间转换jquery,时间转换为数字
文章来源:http://cdkjz.cn/article/phhhcp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220