這個不能直接轉(zhuǎn)換。只能自己編寫。
專注于為中小企業(yè)提供成都網(wǎng)站建設(shè)、做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)義馬免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了成百上千企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
下面是簡單的例子。并有基本注釋:
(function($)?{
$.extend({
myTime:?{
/**
*?當(dāng)前時間戳
*?@return?int????????unix時間戳(秒)??
*/
CurTime:?function(){
return?Date.parse(new?Date())/1000;
},
/**??????????????
*?日期?轉(zhuǎn)換為?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;
},
/**??????????????
*?時間戳轉(zhuǎn)換日期??????????????
*?@param?int?unixTime????待時間戳(秒)??????????????
*?@param?bool?isFull????返回完整時間(Y-m-d?或者?Y-m-d?H:i:s)??????????????
*?@param?int??timeZone???時區(qū)??????????????
*/
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里格式化時間采用日期format函數(shù):
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、運行結(jié)果:
06-Aug-2012 2012/06/Aug Monday, August 06, 2012
在javascript中直接輸出Date得到的結(jié)果是這樣的:
function date(){
var date = new Date();
alert(date);
}
結(jié)果是:Mon Jun 15 15:30:46 UTC+0800 2009
得到new Date()型中各個時間級別(年、月、日、時、分、秒)的數(shù):
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+"秒" );
}
得到的結(jié)果就是:Mon Jun 15 15:44:50 UTC+0800 2009 | 2009年6月15日15時44分50秒
分享標(biāo)題:時間轉(zhuǎn)換jquery,時間轉(zhuǎn)換為數(shù)字
網(wǎng)站URL:http://sd-ha.com/article28/phhhcp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗、自適應(yīng)網(wǎng)站、域名注冊、品牌網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)