Date.today().add( { days: 1, months: 1 } ) new Date().add( { years: -1 } )
Date.today().set( { day: 20, month: 1 } ) new Date().set( { millisecond: 0 } )
CUSTOM DATE AND TIME FORMAT STRINGS Format Description Example ------ --------------------------------------------------------------------------- ----------------------- s The seconds of the minute between 0-59. "0" to "59" ss The seconds of the minute with leading zero if required. "00" to "59" m The minute of the hour between 0-59. "0" or "59" mm The minute of the hour with leading zero if required. "00" or "59" h The hour of the day between 1-12. "1" to "12" hh The hour of the day with leading zero if required. "01" to "12" H The hour of the day between 0-23. "0" to "23" HH The hour of the day with leading zero if required. "00" to "23" d The day of the month between 1 and 31. "1" to "31" dd The day of the month with leading zero if required. "01" to "31" ddd Abbreviated day name. $C.abbreviatedDayNames. "Mon" to "Sun" dddd The full day name. $C.dayNames. "Monday" to "Sunday" M The month of the year between 1-12. "1" to "12" MM The month of the year with leading zero if required. "01" to "12" MMM Abbreviated month name. $C.abbreviatedMonthNames. "Jan" to "Dec" MMMM The full month name. $C.monthNames. "January" to "December" yy The year as a two-digit number. "99" or "08" yyyy The full four digit year. "1999" or "2008" t Displays the first character of the A.M./P.M. designator. "A" or "P" $C.amDesignator or $C.pmDesignator tt Displays the A.M./P.M. designator. "AM" or "PM" $C.amDesignator or $C.pmDesignator S The ordinal suffix ("st, "nd", "rd" or "th") of the current day. "st, "nd", "rd" or "th" || *Format* || *Description* || *Example* || || d || The CultureInfo shortDate Format Pattern || "M/d/yyyy" || || D || The CultureInfo longDate Format Pattern || "dddd, MMMM dd, yyyy" || || F || The CultureInfo fullDateTime Format Pattern || "dddd, MMMM dd, yyyy h:mm:ss tt" || || m || The CultureInfo monthDay Format Pattern || "MMMM dd" || || r || The CultureInfo rfc1123 Format Pattern || "ddd, dd MMM yyyy HH:mm:ss GMT" || || s || The CultureInfo sortableDateTime Format Pattern || "yyyy-MM-ddTHH:mm:ss" || || t || The CultureInfo shortTime Format Pattern || "h:mm tt" || || T || The CultureInfo longTime Format Pattern || "h:mm:ss tt" || || u || The CultureInfo universalSortableDateTime Format Pattern || "yyyy-MM-dd HH:mm:ssZ" || || y || The CultureInfo yearMonth Format Pattern || "MMMM, yyyy" || STANDARD DATE AND TIME FORMAT STRINGS Format Description Example ("en-US") ------ --------------------------------------------------------------------------- ----------------------- d The CultureInfo shortDate Format Pattern "M/d/yyyy" D The CultureInfo longDate Format Pattern "dddd, MMMM dd, yyyy" F The CultureInfo fullDateTime Format Pattern "dddd, MMMM dd, yyyy h:mm:ss tt" m The CultureInfo monthDay Format Pattern "MMMM dd" r The CultureInfo rfc1123 Format Pattern "ddd, dd MMM yyyy HH:mm:ss GMT" s The CultureInfo sortableDateTime Format Pattern "yyyy-MM-ddTHH:mm:ss" t The CultureInfo shortTime Format Pattern "h:mm tt" T The CultureInfo longTime Format Pattern "h:mm:ss tt" u The CultureInfo universalSortableDateTime Format Pattern "yyyy-MM-dd HH:mm:ssZ" y The CultureInfo yearMonth Format Pattern "MMMM, yyyy"
Date.today().next().friday(); Date.today().next().fri(); Date.today().next().march(); Date.today().next().mar(); Date.today().next().week();
Date.next().friday(); Date.next().fri(); Date.next().march(); Date.next().mar(); Date.next().week();
Date.today().last().friday(); Date.today().last().fri(); Date.today().last().march(); Date.today().last().mar(); Date.today().last().week();
Date.last().friday(); Date.last().fri(); Date.previous().march(); Date.prev().mar(); Date.last().week();
Date.today().is().friday(); // true|false Date.today().is().fri(); Date.today().is().march(); Date.today().is().mar();
var d1 = Date.today(); // today at 00:00 var d2 = new Date(); // exactly now. // Do they occur on the same day? d1.same().day(d2); // true // Do they occur on the same hour? d1.same().hour(d2); // false, unless d2 hour is '00' (midnight). // What if it's the same day, but one year apart? var nextYear = Date.today().add(1).year(); d1.same().day(nextYear); // false, because the dates must occur on the exact same day.
var future = Date.today().add(2).months(); return someDate.same().week(future); // true|false;
someDate.is().today(); // true|false new Date().is().today(); // true Date.today().is().today();// true Date.today().add(-1).day().is().today(); // false
Date.today().is().weekday(); // true|false
// Set time to 6:15pm with a String Date.today().at("6:15pm"); // Set time to 6:15pm with a config object Date.today().at({hour:18, minute:15});
// Undeclared Numbers must be wrapped with parentheses. Requirment of JavaScript. (3).days().fromNow(); (6).months().fromNow(); // Declared Number variables do not require parentheses. var n = 6; n.months().fromNow();
// Undeclared Numbers must be wrapped with parentheses. Requirment of JavaScript. (3).days().ago(); (6).months().ago(); // Declared Number variables do not require parentheses. var n = 6; n.months().ago();
var o = new Date().toObject(); // { year: 2008, month: 4, week: 20, day: 13, hour: 18, minute: 9, second: 32, millisecond: 812 } // The object properties can be referenced directly from the object. alert(o.day); // alerts "13" alert(o.year); // alerts "2008"
var o = new Date().toObject(); return Date.fromObject(o); // will return the same date. var o2 = {month: 1, day: 20, hour: 18}; // birthday party! Date.fromObject(o2);
/////////// // Dates // /////////// // 15-Oct-2004 var d1 = Date.parse("10/15/2004"); // 15-Oct-2004 var d1 = Date.parse("15-Oct-2004"); // 15-Oct-2004 var d1 = Date.parse("2004.10.15"); //Fri Oct 15, 2004 var d1 = Date.parse("Fri Oct 15, 2004"); /////////// // Times // /////////// // Today at 10 PM. var d1 = Date.parse("10 PM"); // Today at 10:30 PM. var d1 = Date.parse("10:30 P.M."); // Today at 6 AM. var d1 = Date.parse("06am"); ///////////////////// // Dates and Times // ///////////////////// // 8-July-2004 @ 10:30 PM var d1 = Date.parse("July 8th, 2004, 10:30 PM"); // 1-July-2004 @ 10:30 PM var d1 = Date.parse("2004-07-01T22:30:00"); //////////////////// // Relative Dates // //////////////////// // Returns today's date. The string "today" is culture specific. var d1 = Date.parse("today"); // Returns yesterday's date. The string "yesterday" is culture specific. var d1 = Date.parse("yesterday"); // Returns the date of the next thursday. var d1 = Date.parse("Next thursday"); // Returns the date of the most previous monday. var d1 = Date.parse("last monday"); // Returns today's day + one year. var d1 = Date.parse("next year"); /////////////// // Date Math // /////////////// // Today + 2 days var d1 = Date.parse("t+2"); // Today + 2 days var d1 = Date.parse("today + 2 days"); // Today + 3 months var d1 = Date.parse("t+3m"); // Today - 1 year var d1 = Date.parse("today - 1 year"); // Today - 1 year var d1 = Date.parse("t-1y"); ///////////////////////////// // Partial Dates and Times // ///////////////////////////// // July 15th of this year. var d1 = Date.parse("July 15"); // 15th day of current day and year. var d1 = Date.parse("15"); // July 1st of current year at 10pm. var d1 = Date.parse("7/1 10pm");
// 15-Oct-2004 var d1 = Date.parseExact("10/15/2004", "M/d/yyyy"); // 15-Oct-2004 var d1 = Date.parse("15-Oct-2004", "M-ddd-yyyy"); // 15-Oct-2004 var d1 = Date.parse("2004.10.15", "yyyy.MM.dd"); // Multiple formats var d1 = Date.parseExact("10/15/2004", ["M/d/yyyy", "MMMM d, yyyy"]);