[英]Javascript Converting IETF Date to ISO8601 Format
我正在使用這個很棒的jQuery日歷插件
http://arshaw.com/fullcalendar/
單擊日期的選項之一是回調函數,用於返回單擊的日期。
http://arshaw.com/fullcalendar/docs/mouse/dayClick/
我相信它只會以這種格式返回日期IETF格式-2009年10月18日,星期三,美國東部標准時間
但是,我需要采用ISO861格式來發布數據。 我似乎在Google上找不到任何東西。 我正在嘗試將其轉換為Javascript。 如果不是,則轉換可以在Java后端中進行。 感謝幫助
由於dayClick已經為您提供了Javascript Date對象,因此您可以使用Mozilla網站中的此函數將其格式化為8601格式的日期字符串。
它返回一個常規的javascript日期對象。 您可以像這樣使用fullcalendar formatDate
實用程序函數:
$.fullCalendar.formatDate(date, 'u');
您可以使用屬於Date對象dayClick的formatDate函數!
function getGMTOffset(localDate) {
var positive = (localDate.getTimezoneOffset() > 0);
var aoff = Math.abs(localDate.getTimezoneOffset());
var hours = Math.floor(aoff / 60);
var mins = aoff % 60;
var offsetTz = padzero_(hours) + ':' + padzero_(mins);
// getTimezoneOffset() method returns difference between (GMT) and local time, in minutes.
// example, If your time zone is GMT+2, -120 will be returned.
// This is why we are inverting sign
if (!positive) {
return '+' + offsetTz;
}
return '-' + offsetTz;
}
function pad2zeros(n) {
if (n < 100) {
n = '0' + n;
}
if (n < 10) {
n = '0' + n;
}
return n;
}
function padzero(n) {
return n < 10 ? '0' + n : n.toString();
}
function formatDate(date) {
if (date) {
return (date.getFullYear()) +
'-' + padzero((date.getMonth() + 1)) +
'-' + padzero(date.getDate()) +
'T' + padzero(date.getHours()) +
':' + padzero(date.getMinutes()) +
':' + padzero(date.getSeconds()) +
'.' + pad2zeros(date.getMilliseconds()) +
getGMTOffset(date);
}
return '';
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.