|
0
|
1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
|
2 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
|
|
3 |
<head> |
|
|
4 |
<title>Javascript date formatting demo</title> |
|
|
5 |
<script type="text/javascript" src="date-functions.js"></script> |
|
|
6 |
<link rel="stylesheet" type="text/css" href="../files/demo-style.css" /> |
|
|
7 |
</head> |
|
|
8 |
|
|
|
9 |
<body> |
|
|
10 |
|
|
|
11 |
<p>The following demo loops through several sample formatting strings and all pre-defined patterms, and creates a table of the results:</p> |
|
|
12 |
|
|
|
13 |
<script type="text/javascript">var formats = [ |
|
|
14 |
"Y-m-d", |
|
|
15 |
"n/j/y", |
|
|
16 |
"l, M jS, Y", |
|
|
17 |
"Y-m-d H:i:s", |
|
|
18 |
"D \\t\\h\e jS"]; |
|
|
19 |
var d = new Date(); |
|
|
20 |
document.write("<table class='borders collapsed'><tr><th colspan='2'>Format Strings<" + "/th><" + "/tr>"); |
|
|
21 |
for (var f in formats) { |
|
|
22 |
document.write("<tr><td>" + formats[f] + "<" + "/td><td>" + d.dateFormat(formats[f]) + "<" + "/td><" + "/tr>"); |
|
|
23 |
} |
|
|
24 |
document.write("<tr><th colspan='2'>Pre-Defined Patterns<" + "/th><" + "/tr>"); |
|
|
25 |
for (var f in Date.patterns) { |
|
|
26 |
document.write("<tr><td>Date.patterns." + f + "<" + "/td><td>" + d.dateFormat(Date.patterns[f]) + "<" + "/td><" + "/tr>"); |
|
|
27 |
} |
|
|
28 |
document.write("<" + "/table>"); |
|
|
29 |
</script> |
|
|
30 |
|
|
|
31 |
<p>The following table lists the code for each of the functions generated as a result of parsing the format strings:</p> |
|
|
32 |
|
|
|
33 |
<script type="text/javascript"> |
|
|
34 |
document.write("<table class='borders collapsed'><tr><th>Function<" + "/th><th>Code<" + "/th><" + "/tr>"); |
|
|
35 |
for (var f in Date.formatFunctions) { |
|
|
36 |
if (f !== "count") { |
|
|
37 |
document.write("<tr><td>" + Date.formatFunctions[f] + "<" + "/td><td>" + Date.prototype[Date.formatFunctions[f]] + "<" + "/td><" + "/tr>"); |
|
|
38 |
} |
|
|
39 |
} |
|
|
40 |
document.write("<" + "/table>"); |
|
|
41 |
</script> |
|
|
42 |
|
|
|
43 |
|
|
|
44 |
</body> |
|
|
45 |
</html> |