FullCalendar Date Format

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

This is actually:
Tue Aug 13 2013 18:00:00 GMT-0400 (EDT)

I want:
2013-08-13

Thanks.

+4
source share
2 answers

For information specific to FullCalendar, you probably need to see this , which gives you some formatting rules. Additional information may be helpful here.


However, you can do this using JavaScript directly if you need this date format in the interface between FullCalendar and another package or your own code:

If you want today, you can (be careful, as this will be the client side):

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

And from the line 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 will give you the ISO date in UTC. For a locale date, you must “move” your time object to UTC before using .toISOString . Let be:

 > 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' 

The language may still be different from GMT-0400 given in your example (here it is GMT-0300, at the end it gives me 1 hour after that in this example).


I will reproduce here the information from the first FullCalendar link that I said:

FormatDate

Formats a Date object into a string.

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

Prior to version 1.3, the formatDate format adopted a completely 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 - clock, 12 hour clock, 2 digits
  • H - watch, 24-hour format
  • HH - watch, 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 - full month name
  • 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 date
  • W - week number ISO8601

Special symbols:

'...' literal text

'' single quote (represented by two single quotes)

(...) only displays the format if one of the private variables is nonzero

The options parameter can be used to override standard locale options such as monthNames , monthNamesShort , dayNames, and dayNamesShort .

+7
source

My decision:

  select: function (start, end, allDay) { var startFix= moment($.fullCalendar.formatDate(start, 'YYYY-MM-DD')); newCalendar(startFix); } 
0
source

Source: https://habr.com/ru/post/898289/


All Articles