Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
596 views
in Technique[技术] by (71.8m points)

javascript - FullCalendar date format

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...