javascript 全日历日期格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18551331/
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 format
提问by Francois
Want to find the way to change the default date format in FullCalendar.
想找到在 FullCalendar 中更改默认日期格式的方法。
Actually, it is:
Tue Aug 13 2013 18:00:00 GMT-0400 (EDT)
实际上,它是:
2013 年 8 月 13 日星期二 18:00:00 GMT-0400 (EDT)
I want:
2013-08-13
我要:
2013-08-13
Thanks.
谢谢。
回答by H.D.
For information specific to the FullCalendar, you probably need to see this, which gives you some formating rules. There's some more information herethat might be useful.
有关 FullCalendar 的特定信息,您可能需要查看此,它为您提供了一些格式规则。有一些更多的信息在这里,可能是有用的。
Yet, you can do so with JavaScript directly if you need this date format in an interface between the FullCalendar and other package or your own code:
但是,如果您需要在 FullCalendar 和其他包或您自己的代码之间的接口中使用此日期格式,则可以直接使用 JavaScript 执行此操作:
If you want "today", you can (be careful since that'll be client-side):
如果你想要“今天”,你可以(小心,因为那将是客户端):
> (new Date()).toISOString().slice(0, 10)
'2013-08-31'
And from the string you said, you can:
从你说的字符串中,你可以:
> dateStr = "Tue Aug 13 2013 18:00:00 GMT-0400 (EDT)"
> (new Date(dateStr)).toISOString().slice(0, 10)
'2013-08-13'
Both would give you the ISO date in UTC. For locale date, you should "move" your time object to UTC before using .toISOString
. Let:
两者都会为您提供 UTC 格式的 ISO 日期。对于语言环境日期,您应该在使用.toISOString
. 让:
> dateStr = "Mon Aug 12 2013 22:00:00 GMT-0400 (EDT)"
> dateObj = new Date(dateStr) /* Or empty, for today */
> dateIntNTZ = dateObj.getTime() - dateObj.getTimezoneOffset() * 60 * 1000
> dateObjNTZ = new Date(dateIntNTZ)
> dateObjNTZ.toISOString().slice(0, 10)
'2013-08-12'
Locale can still be different from GMT-0400 given in your example (here it's GMT-0300, at the end it gives me 1 hour after the one in this example).
区域设置仍然可能与您的示例中给出的 GMT-0400 不同(这里是 GMT-0300,最后它在本示例中的那个之后给了我 1 小时)。
I'll replicate here the information from the first FullCalendar link I said:
我将在此处复制我说的第一个 FullCalendar 链接中的信息:
formatDate
格式日期
Formats a Date object into a string.
将 Date 对象格式化为字符串。
$.fullCalendar.formatDate( date, formatString [, options ] ) -> String
Prior to version 1.3, formatDate accepted a very different format. See here.
在 1.3 版之前,formatDate 接受一种非常不同的格式。见这里。
formatString
is a combination of any of the following commands:
formatString
是以下任何命令的组合:
- s- seconds
- ss- seconds, 2 digits
- m- minutes
- mm- minutes, 2 digits
- h- hours, 12-hour format
- hh- hours, 12-hour format, 2 digits
- H- hours, 24-hour format
- HH- hours, 24-hour format, 2 digits
- d- date number
- dd- date number, 2 digits
- ddd- date name, short
- dddd- date name, full
- M- month number
- MM- month number, 2 digits
- MMM- month name, short
- MMMM- month name, full
- yy- year, 2 digits
- yyyy- year, 4 digits
- t- 'a' or 'p'
- tt- 'am' or 'pm'
- T- 'A' or 'P'
- TT- 'AM' or 'PM'
- u- ISO8601 format
- S- 'st', 'nd', 'rd', 'th' for the date
- W- the ISO8601 week number
- s- 秒
- ss- 秒,2 位数字
- m- 分钟
- mm- 分钟,2 位数字
- h- 小时,12 小时制
- hh- 小时,12 小时制,2 位数字
- H- 小时,24 小时制
- HH- 小时,24 小时制,2 位数字
- d- 日期编号
- dd- 日期编号,2 位数字
- ddd- 日期名称,简称
- dddd- 日期名称,完整
- M- 月数
- MM- 月份编号,2 位数字
- MMM- 月份名称,简称
- MMMM- 月份名称,完整
- yy- 年份,2 位数字
- yyyy- 年份,4 位数字
- t- 'a' 或 'p'
- tt- 'am' 或 'pm'
- T- 'A' 或 'P'
- TT- “上午”或“下午”
- u- ISO8601 格式
- S- 'st', 'nd', 'rd', 'th' 表示日期
- W- ISO8601 周数
Special Characters:
特殊字符:
'...'
literal text
'...'
文字
''
single quote (represented by two single quotes)
''
单引号(用两个单引号表示)
(...)
only displays format if one of the enclosed variables is non-zero
(...)
仅当封闭变量之一为非零时才显示格式
The options
parameter can be used to override default locale options, such as monthNames, monthNamesShort, dayNames, and dayNamesShort.
该options
参数可用于覆盖默认语言环境选项,例如monthNames、monthNamesShort、dayNames和dayNamesShort。
回答by Alejandro Aranda
My solution:
我的解决方案:
select: function (start, end, allDay) {
var startFix= moment($.fullCalendar.formatDate(start, 'YYYY-MM-DD'));
newCalendar(startFix);
}