/* * Date.getFormatedString(format) * Author: MattWalker * http://proto.layer51.com/d.aspx?f=1139 */ Date.prototype.getFormatedString = function(format) { var keys = {y:"getFullYear", m:"getMonth", d:"getDate", h:"getHours", n:"getMinutes", s:"getSeconds", i:"getMilliseconds"}; var str = ""; var ci, meth; for (var i = 0; i < format.length; i++) { ci = format.charAt(i); if (keys[ci] != undefined) { meth = keys[ci]; if (meth == "getMonth") { var val = (this[meth]() + 1); str += (val < 10) ? "0" + val : val; } else { var val = (this[meth]()); str += (val < 10) ? "0" + val : val; } } else { str += ci; } } return str; }; //////////////////////////////////////usage//////////////////props to: MattWalker//// var now = new Date(); trace(now.getFormatedDate("y-m-d h:n:s")); trace(now.getFormatedDate("d/m/y")); trace(now.getFormatedDate("d.m.y"));
Date.getFormatedDate
Page 1 of 11 Replies - 1406 Views - Last Post: 17 January 2008 - 09:14 AM
#1
Date.getFormatedDate
Posted 01 May 2006 - 06:39 AM
Description: place the script in the first frame of your movie. instructions of usage are in the script itself.gives you the time and date already formated. What a time saver!!! ;)
Author: MattWalker
Original: http://proto.layer51.com/d.aspx?f=1139
Replies To: Date.getFormatedDate
#2
Re: Date.getFormatedDate
Posted 17 January 2008 - 09:14 AM
The code actually has a typographical error:
On lines 30 through 32, it says now.getFormatedDate, however, the actual prototype name is "now.getFormatedString".
So either lines 30-32 should be changed to now.getFormatedString OR line 7 needs to be changed to getFormatedDate.
Works fine other than that. It would be nice to see it mention the actual day and month (e.g. Thursday, January 17, 2007)
Page 1 of 1