forked from moment/moment
/
index.html
99 lines (73 loc) · 4.34 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>timrwood | underscore.date @ GitHub</title>
<link rel='stylesheet' href='http://fonts.googleapis.com/css?family=Oswald&v1'>
<link rel="stylesheet" href="site/style.css">
</head>
<body>
<a class="fork-me" href="http://github.com/timrwood/underscore.date">Fork me on Github</a>
<div id="container">
<h1 class="logo">
<a href="http://github.com/timrwood/underscore.date">underscore.date</a>
<span class="small">by <a href="http://github.com/timrwood">timrwood</a></span>
</h1>
<h2 class="ca">Parsing + Manipulation + Formatting + Timeago + I18n + NodeJS</h2>
<h3 class="ca">And all without modifying the native Date prototype, so it's safe for kids!</h3>
<div class="br"> </div>
<div class="col-1">
<h2>What is this?</h2>
<p>Underscore.date is a javascript date library that helps parse, manipulate, and format dates.</p>
<p>It doesn't modify the native `Date` prototype, so it's safe to drop into any site.</p>
<p>While not dependant on <a href="http://documentcloud.github.com/underscore/">underscore</a>, it does follow
the same philosophy, and if underscore exists on your page, underscore.date will mix itself in.</p>
</div>
<div class="col-1">
<h2>Download : 2.02 kb (min + gzip)</h2>
<p>You can download this project in either
<a href="http://github.com/timrwood/underscore.date/zipball/master">zip</a> or
<a href="http://github.com/timrwood/underscore.date/tarball/master">tar</a> formats.
</p>
<p>You can also clone the project with <a href="http://git-scm.com">Git</a> by running:
<pre>$ git clone git://github.com/timrwood/underscore.date</pre>
</p>
</div>
<div class="clearfix"></div>
<div class="br"> </div>
<h1>Works in the browser and in Node.js!</h1>
<h3>Node.js</h3>
<pre><code>npm install underscore.date</code></pre>
<pre><code>var _date = require('underscore.date');
console.log(_date('September 9 1999').fromNow());</code></pre>
<h3>In the browser</h3>
<p>If underscore exists, underscore.date will mix itself into the underscore namespace, so you can use as you would use an underscore function.</p>
<pre><code>_.date('September 9 1999').fromNow();</code></pre>
<p>Otherwise, you should use <code>_date</code>.</p>
<pre><code>_date('September 9 1999').fromNow();</code></pre>
<h2>Examples</h2>
<p>Format a Unix timestamp</p>
<pre><code>_date(1300291340510).format("MMMM Do, YYYY") // >>> "March 16th, 2011" </code></pre>
<p>Get timeago for a date string</p>
<pre><code>_date("7-10-1986", "MM-DD-YYYY").fromNow() // >>> "25 years ago" </code></pre>
<p>Get the current time and add 3 hours</p>
<pre><code>_date().add({h:3}).fromNow() // >>> "in 3 hours" </code></pre>
<p>Change the language</p>
<pre><code>_date(1300291340510).format("MMMM Do, YYYY") // >>> "March 16th, 2011"
_date.lang('pt');
_date(1300291340510).format("MMMM Do, YYYY") // >>> "Março 16o, 2011"
_date.lang('en');
_date(1300291340510).format("MMMM Do, YYYY") // >>> "March 16th, 2011"</code></pre>
<h2>Tests</h2>
<h3><a href="test/test.html">underscore.date unit tests</h3>
<h3><a href="http://jsperf.com/underscore-date">underscore.date performance tests</a></h3>
<h3>Full source code and documentation at <a href="http://github.com/timrwood/underscore.date">http://github.com/timrwood/underscore.date</a></h3>
</div>
<script>
var _gaq=[['_setAccount','UA-10641787-5'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
</body>
</html>