FullCalendar日期格式 [英] FullCalendar date format

查看:247
本文介绍了FullCalendar日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



其实,它是:

星期二8月13 2013 18:00:00 GMT-0400(美国东部时间)



我想:

2013- 08-13



感谢。 FullCalendar,你可能需要看这个,它给你一些格式规则。 此处有更多信息可能有用。






然而,如果您在FullCalendar与其他包或您自己的代码之间的界面中需要此日期格式,则可以直接使用JavaScript执行此操作:



如果你想要今天,你可以(小心,因为这将是客户端):

 > (new Date())。toISOString()。slice(0,10)
'2013-08-31'

从你说的字符串中,你可以:

 > dateStr =Tue Aug 13 2013 18:00:00 GMT-0400(EDT)
> (new Date(dateStr))。toISOString()。slice(0,10)
'2013-08-13'

两者都会以UTC为单位给出ISO日期。对于语言环境日期,在使用 .toISOString 之前,应该将时间对象移动到UTC。让:

 > dateStr =Mon Aug 12 2013 22:00:00 GMT-0400(EDT)
> dateObj = new Date(dateStr)/ *或者为空,今天* /
> dateIntNTZ = dateObj.getTime() - dateObj.getTimezoneOffset()* 60 * 1000
> dateObjNTZ =新日期(dateIntNTZ)
> dateObjNTZ.toISOString()。slice(0,10)
'2013-08-12'

在您的示例中,区域设置仍可能不同于GMT-0400(这里是GMT-0300,最后它会在本例中的一小时后给出我)。





formatDate

$

我会在这里复制第一个FullCalendar链接的信息。 b
$ b

将Date对象格式化为字符串。

  $。fullCalendar.formatDate(date, formatString [,options]) - >字符串

在版本1.3之前,formatDate接受了一种非常不同的格式。请参阅此处



formatString 是以下任何命令的组合:


  • s
  • 分钟
  • mm - 分钟,2位数字

  • h - 小时,12小时格式

  • hh - 小时,12小时格式,2位数字

  • H - 小时,24小时制格式

  • HH - 小时,24小时格式,2位数字

  • d
  • ddd > - 日期名称,简称

  • dddd - 日期名称,全部
  • M - 月数

  • MM - 月份数字,2位数字

  • MMM - 月份名称,简称

  • MMMM - 月份名称,全部
  • yy - 年份,2位数字

  • yyyy - 年份,4位数字 / strong> - 'a'或'p'

  • tt - 'am'或'pm'

  • < 'A'或'P'

  • TT - 'AM'或'PM'

  • u - ISO8601格式

  • S - 'st','nd','rd','th'日期

  • W - ISO8601周数



特殊字符:

'...'
文字文本



''
单引号(用两个单引号表示)

(...)
只显示其中一个封闭变量的格式是非零的

options 参数可以用来覆盖默认的语言环境选项,比如 monthNames monthNamesShort dayNames 和< href =http://arshaw.com/fullcalendar/docs/text/dayNamesShort/ =noreferrer> dayNamesShort 。


Want to find the way to change the default date format in FullCalendar.

Actually, it is:
Tue Aug 13 2013 18:00:00 GMT-0400 (EDT)

I want:
2013-08-13

Thanks.

解决方案

For information specific to the FullCalendar, you probably need to see this, which gives you some formating rules. There's some more information here that might be useful.


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:

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:

> 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).


I'll replicate here the information from the first FullCalendar link I said:

formatDate

Formats a Date object into a string.

$.fullCalendar.formatDate( date, formatString [, options ] ) -> String

Prior to version 1.3, formatDate accepted a very different format. See here.

formatString is a combination of any of the following commands:

  • 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

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.

这篇关于FullCalendar日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆