{infiniteZest}
// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
AJAX
Apple
ASP.NET
.NET
Git
Google / Android
Python / IronPython
Miscellaneous
SQL Server
AJAX Source Viewer
View the source code of a Method from ASP.NET AJAX Library. Choose a method from the menu items above (Namespaces, Classes, or Methods).
Method 'prototype._toFormattedString(format, cultureInfo)'
Method: prototype._toFormattedString(format, cultureInfo)
Method Full Name:     Date$_toFormattedString(format, cultureInfo)
Class: Date
Namespace: Global (MicrosoftAjax.debug.js)
Source File: MicrosoftAjax.debug.js
1   Date.prototype._toFormattedString = function Date$_toFormattedString(format, cultureInfo) {
2     if (!format || (format.length === 0) || (format === 'i')) {
3       if (cultureInfo && (cultureInfo.name.length > 0)) {
4         return this.toLocaleString();
5       }
6       else {
7         return this.toString();
8       }
9     }
10    var dtf = cultureInfo.dateTimeFormat;
11    format = Date._expandFormat(dtf, format);
12    var ret = new Sys.StringBuilder();
13    var hour;
14    function addLeadingZero(num) {
15      if (num < 10) {
16        return '0' + num;
17      }
18      return num.toString();
19    }
20    function addLeadingZeros(num) {
21      if (num < 10) {
22        return '00' + num;
23      }
24      if (num < 100) {
25        return '0' + num;
26      }
27      return num.toString();
28    }
29    var quoteCount = 0;
30    var tokenRegExp = Date._getTokenRegExp();
31    for (;;) {
32      var index = tokenRegExp.lastIndex;
33      var ar = tokenRegExp.exec(format);
34      var preMatch = format.slice(index, ar ? ar.index : format.length);
35      quoteCount += Date._appendPreOrPostMatch(preMatch, ret);
36      if (!ar) break;
37      if ((quoteCount%2) === 1) {
38        ret.append(ar[0]);
39        continue;
40      }
41      switch (ar[0]) {
42        case "dddd":
43          ret.append(dtf.DayNames[this.getDay()]);
44          break;
45        case "ddd":
46          ret.append(dtf.AbbreviatedDayNames[this.getDay()]);
47          break;
48        case "dd":
49          ret.append(addLeadingZero(this.getDate()));
50          break;
51        case "d":
52          ret.append(this.getDate());
53          break;
54        case "MMMM":
55          ret.append(dtf.MonthNames[this.getMonth()]);
56          break;
57        case "MMM":
58          ret.append(dtf.AbbreviatedMonthNames[this.getMonth()]);
59          break;
60        case "MM":
61          ret.append(addLeadingZero(this.getMonth() + 1));
62          break;
63        case "M":
64          ret.append(this.getMonth() + 1);
65          break;
66        case "yyyy":
67          ret.append(this.getFullYear());
68          break;
69        case "yy":
70          ret.append(addLeadingZero(this.getFullYear() % 100));
71          break;
72        case "y":
73          ret.append(this.getFullYear() % 100);
74          break;
75        case "hh":
76          hour = this.getHours() % 12;
77          if (hour === 0) hour = 12;
78          ret.append(addLeadingZero(hour));
79          break;
80        case "h":
81          hour = this.getHours() % 12;
82          if (hour === 0) hour = 12;
83          ret.append(hour);
84          break;
85        case "HH":
86          ret.append(addLeadingZero(this.getHours()));
87          break;
88        case "H":
89          ret.append(this.getHours());
90          break;
91        case "mm":
92          ret.append(addLeadingZero(this.getMinutes()));
93          break;
94        case "m":
95          ret.append(this.getMinutes());
96          break;
97        case "ss":
98          ret.append(addLeadingZero(this.getSeconds()));
99          break;
100       case "s":
101         ret.append(this.getSeconds());
102         break;
103       case "tt":
104         ret.append((this.getHours() < 12) ? dtf.AMDesignator : dtf.PMDesignator);
105         break;
106       case "t":
107         ret.append(((this.getHours() < 12) ? dtf.AMDesignator : dtf.PMDesignator).charAt(0));
108         break;
109       case "f":
110         ret.append(addLeadingZeros(this.getMilliseconds()).charAt(0));
111         break;
112       case "ff":
113         ret.append(addLeadingZeros(this.getMilliseconds()).substr(0, 2));
114         break;
115       case "fff":
116         ret.append(addLeadingZeros(this.getMilliseconds()));
117         break;
118       case "z":
119         hour = this.getTimezoneOffset() / 60;
120         ret.append(((hour <= 0) ? '+' : '-') + Math.floor(Math.abs(hour)));
121         break;
122       case "zz":
123         hour = this.getTimezoneOffset() / 60;
124         ret.append(((hour <= 0) ? '+' : '-') + addLeadingZero(Math.floor(Math.abs(hour))));
125         break;
126       case "zzz":
127         hour = this.getTimezoneOffset() / 60;
128         ret.append(((hour <= 0) ? '+' : '-') + addLeadingZero(Math.floor(Math.abs(hour))) +
129         dtf.TimeSeparator + addLeadingZero(Math.abs(this.getTimezoneOffset() % 60)));
130         break;
131       }
132     }
133     return ret.toString();
134   }
This is the JavaScript source for method prototype._toFormattedString(format, cultureInfo) from ASP.NET AJAX Library. Full name for this method is Date$_toFormattedString(format, cultureInfo). It belongs to the class Date, which is in Global (MicrosoftAjax.debug.js) namespace. This source is in MicrosoftAjax.debug.js file.
Bookmark and Share This
About  Contact  Privacy Policy  Site Map