Javascript FullCalendar 日期和时间处理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7598142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FullCalendar date & time handling
提问by Oseer
I am using the FullCalendar scriptand am having trouble formatting the date/time of EVENTS on the calendar.
我正在使用FullCalendar 脚本,但无法在日历上格式化 EVENTS 的日期/时间。
I need all the events date/time data to look like:
我需要所有事件日期/时间数据看起来像:
2011-09-28 08:15:00
2011-09-28 08:15:00
All the dates are like this in my JSON source, which display on the calendar correctly. However, if the event is moved or a new event is added (dropped by eternal dragging), the time format looks like:
我的 JSON 源中的所有日期都是这样的,它们在日历上正确显示。但是,如果事件被移动或添加了新事件(通过永久拖拽删除),时间格式如下所示:
Fri Sep 30 2011 14:30:00 GMT-0400 (EDT)
2011 年 9 月 30 日星期五 14:30:00 GMT-0400 (EDT)
It doesn't DISPLAY in that format, but it appears this way when I try to insert the event.start or event.end into my database, or when I do this:
它不会以那种格式显示,但是当我尝试将 event.start 或 event.end 插入我的数据库时,或者当我这样做时,它会以这种方式显示:
eventClick: function(event) {
alert("Event ID: " + event.id + " Start Date: " + event.start + " End Date: " + event.end);
}
I am using this only to see how the date & time are saved within the calendar. I need to update my database with new events, but in the format first shown above, but I am having trouble doing this.
我使用它只是为了查看日期和时间是如何保存在日历中的。我需要用新事件更新我的数据库,但采用上面首先显示的格式,但我在这样做时遇到了麻烦。
How do I use the formatDate
function? I see it listed, and the reason I'm asking is because I don't know what to do with it.
如何使用该formatDate
功能?我看到它列出来,我问的原因是因为我不知道该怎么处理它。
I did:
我做了:
$.fullCalendar.formatDate(event.start, 'MM-dd-yyyy');
but that doesn't do anything...
但这没有任何作用......
采纳答案by Paul
what I did, is, first put it in a var, but only seemed to work in IE - FF still produced the IETF format (ex: "Wed, 18 Oct 2009 13:00:00 EST"):
我所做的是,首先将它放在一个 var 中,但似乎只能在 IE 中工作 - FF 仍然生成 IETF 格式(例如:“Wed, 18 Oct 2009 13:00:00 EST”):
var formDate = $.fullCalendar.formatDate(event.start, 'MM-dd-yyyy');
alert(" Start Date: " + formDate);
回答by Boldbayar
Just use the following code before you render your events:
只需在呈现事件之前使用以下代码:
start=moment(start).format('YYYY/MM/DD hh:mm');
end=moment(end).format('YYYY/MM/DD hh:mm');
Make sure you are using moment.js.
确保您使用的是 moment.js。
回答by pravin deshmukh
I have used below code while rendering the event on calendar.
我在日历上呈现事件时使用了以下代码。
Hope this code help you.
希望此代码对您有所帮助。
eventRender: function(event, element) {
eventsdate = moment(event.start).format('hh:mm a');
eventedate = moment(event.end).format('hh:mm a');
element.find('.fc-time').html(eventsdate + " - " + eventedate + "<br>");
}
Make sure you are using moment.js
确保您使用的是 moment.js
回答by Vaibhav Jain
If you are trying to pass date object from java to full calendar and using Java 7 or lesser, below function will work for you.
如果您尝试将日期对象从 Java 传递到完整日历并使用 Java 7 或更低版本,则以下函数对您有用。
Date date= new Date("passyourdatestring");
日期 date= new Date("passyourdatestring");
date.toLocaleString();
date.toLocaleString();
And following will be the event object.
以下将是事件对象。
{
{
id: '_jobName' ,
url: 'url ',
title: 'title',
allDay: 'false',
description: 'displayname',
start': 'schedDateTime',
end: date.toLocaleString()
};
};
回答by rails_id
Q : How do I use the formatDate function? I see it listed, the reason I'm asking is because I don't know what to do with it. I did: $.fullCalendar.formatDate(event.start, 'MM-dd-yyyy'); That doesn't do anything...
问:如何使用 formatDate 函数?我看到它被列出,我问的原因是因为我不知道该怎么处理它。我做了: $.fullCalendar.formatDate(event.start, 'MM-dd-yyyy'); 那没有任何作用...
Answer :
回答 :
You can use look likes :
你可以使用看起来像:
eventClick: function(event) {
alert("Event ID: " + event.id + " Start Date: " + $.fullCalendar.formatDate(event.start, 'MM-dd-yyyy') + " End Date: " + event.end);
}
回答by Manza
I have found your answer in a similar question, in here
我在一个类似的问题中找到了你的答案,在这里
Answered by H.D:
高清回复:
dateStr = "Tue Aug 13 2013 18:00:00 GMT-0400 (EDT)"
(new Date(dateStr)).toISOString().slice(0, 10)
It will display: '2013-08-13'
它将显示:'2013-08-13'
(new Date(dateStr)).toISOString()
It will display: '2013-08-13T18:00:00.000Z'
它将显示:'2013-08-13T18:00:00.000Z'
回答by Magnus Winter
Check out formatDateand parseDateand it'll probably solve your problems.
查看formatDate和parseDate,它可能会解决您的问题。