1 Replies - 1103 Views - Last Post: 17 January 2008 - 09:14 AM

#1 reyco1  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 43
  • Joined: 20-March 05

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
/*
 * 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"));


Is This A Good Question/Topic? 0
  • +

Replies To: Date.getFormatedDate

#2 tonedoggydogg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 17-January 08

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)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1