|
|
FAQ Topic - How do I format a Date object with javascript? (2010-01-27)
-----------------------------------------------------------------------
FAQ Topic - How do I format a Date object with javascript?
-----------------------------------------------------------------------
A local ` Date ` object where ` 0 <= year <= 9999 ` can be
formatted to a common ISO 8601 format ` YYYY-MM-DD ` with:-
/** Formats a Date to YYYY-MM-DD (local time), compatible with both
* ISO 8601 and ISO/IEC 9075-2:2003 (E) (SQL 'date' type).
* @param {Date} dateInRange year 0000 to 9999.
* @throws {RangeError} if the year is not in range
*/
function formatDate(dateInRange) {
var year = dateInRange.getFullYear(),
isInRange = year >= 0 && year <= 9999, yyyy, mm, dd;
if(!isInRange) {
throw RangeError("formatDate: year must be 0000-9999");
}
yyyy = ("000" + year).slice(-4);
mm = ("0" + (dateInRange.getMonth() + 1)).slice(-2);
dd = ("0" + (dateInRange.getDate())).slice(-2);
return yyyy + "-" + mm + "-" + dd;
}
http://www.merlyn.demon.co.uk/js-date9.htm
The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/
--
The sendings of these daily posts are proficiently hosted
by http://www.pair.com.
|
|
0
|
|
|
|
Reply
|
javascript4 (1176)
|
1/27/2010 12:00:03 AM |
|
|
0 Replies
1699 Views
(page loaded in 0.026 seconds)
Similiar Articles: Multiple Auto Expire Script - comp.lang.javascript... Why not use the standard Javascript date format for your date ... grasp why they should not change the Date object ... Date(Date.UTC(2010, 6, 1)) or new Date("2010-07-01 00 ... Poker hand evaluator - comp.lang.javascriptA note on the rank format : The first 4 ... gigane ws.com>, Tue, 9 Mar 2010 20:27:02 ... Poker hand evaluator - comp.lang.javascript On the other hand, Objects or ... Which Assembler? - comp.lang.asm.x86BTW, I did scan the FAQ but the latest version is ... he probably discovered that you cannot link in object ... monthly (21st of every month) Last-modified: 2010/01/24 -----... Sampling: What Nyquist Didn't Say, and What to Do About It - comp ...The images appear to be vector format rather than ... On Mon, 20 Dec 2010 01:34:44 -0600, Tim Wescott <tim ... 12/20/2010 9:27:34 PM Where did Fortran go? - comp.lang.fortranOn Tue, 28 Sep 2010 12:27:54 +0200, Tobias ... fortran is still f77!!!They do write an extension "f90"....and free format coding ... On 10/01/2010 10:08 AM, nmm1@cam.ac.uk ... top 10 uses for random data compression?? anyone? - comp ...Will it work on data other than Divx format files? ... How will you object the latin ugly destinations before ... grow as yet while you're stealing around a sole topic. comp.lang.javascript FAQFAQ Topic - What books are recommended for ... 5.1 How do I format a Date object with javascript? ... value close to a multiple of 0.01 ... jquery - How to format a JSON date? - Stack Overflow... to JSON - How do I format this to a short date ... Date(12348721342)/) as well as ISO formatted dates (2010-01-01T12.34.56.789Z ... to receive a Date object in JavaScript? 7/24/2012 9:10:27 AM
|
|
|
|
|
|
|
|
|