0

我正在使用这个很棒的 jQuery 日历插件

http://arshaw.com/fullcalendar/

单击日期的选项之一是返回单击日期的回调函数。

http://arshaw.com/fullcalendar/docs/mouse/dayClick/

我相信它只会以这种格式返回日期 IETF 格式 - Wed, 18 Oct 2009 13:00:00 EST

但是,我需要它以 ISO861 格式发布数据。我似乎在谷歌上找不到任何东西。我正在尝试将其转换为 Javascript。如果没有,那么转换可以在 Java 后端进行。帮助表示赞赏

4

4 回答 4

2

来自精美手册

date保存当天的Date 对象。

强调我的。

我猜您看到的 IETF 格式只是Date对象的默认字符串化。Date 类具有getYear()getMonth()和方法,因此getDate()如果您当然注意零填充,则可以轻松生成 ISO-8601 日期字符串。

于 2011-03-24T05:38:08.473 回答
1

由于 dayClick 已经为您提供了一个 Javascript Date 对象,您可以使用Mozilla 站点中的此函数将其格式化为 8601 格式的日期字符串。

于 2011-03-25T14:42:53.377 回答
0

您可以使用属于您的 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 '';
}
于 2011-10-26T17:43:01.420 回答
0

它返回一个常规的 javascript 日期对象。您可以像这样使用 fullcalendarformatDate实用程序函数:

$.fullCalendar.formatDate(date, 'u');

formatDate 的完整文档

于 2011-04-10T00:06:44.947 回答