我有一個應用程序,我需要將mySQL日期時間標記和倒計時轉換爲當前系統時間。我正在使用keith木jquery倒計時,這是正確安裝和工作...但我不能得到的代碼來轉換我的時間戳工作,以挽救我的生命。jquery mySQL時間戳轉換編碼錯誤
我發現這個代碼片段轉換時間戳,但我得到一個錯誤在我的firefox控制檯讀取:timestamp.replace是不是一個函數。我不是js編碼方面的專家,所以我相信這很明顯。任何人都可以提供的幫助將非常感激。這開始讓我瘋狂。
這是一個rails應用程序。
$(document).ready(function mysqlTimeStampToDate(timestamp) {
//function parses mysql datetime string and returns javascript Date object
//input has to be in this format: 2007-06-05 15:26:02
var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
});
$(document).ready(function() {
$('textLayout').countdown({until: mysqlTimeStampToDate("#work_order_hard_completion_datetime"), layout: '{dn}d {hnn}{sep}{mnn}{sep}{snn}'});
});
萬分感謝。現在效果很好。 – user1214966 2012-02-16 23:12:10