| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 6 |
<title>timeago.js: is a tiny(2kb) library used to format date with `*** time ago`. eg: '3 hours ago'. No dependency.</title> |
| 7 |
<meta name="keywords" content="timeago, timeago.js, datetime,*** time ago, javascript timeago, react-timeago, jquery-timeago, timeago.org" /> |
| 8 |
<meta name="description" content="timeago.js is a tiny(2kb) library used to format date with `*** time ago`. eg: '3 hours ago'. No dependence. and support automatically updating fuzzy timestamps." /> |
| 9 |
<link rel="shortcut icon" href="./clock.png" /> |
| 10 |
<link rel="bookmark" href="./clock.png" /> |
| 11 |
<link rel="stylesheet" type="text/css" href="./css.css" /> |
| 12 |
</head> |
| 13 |
<body> |
| 14 |
<div id="content"> |
| 15 |
<h1><img src="./clock.png" /> timeago.js</h1> |
| 16 |
<h2> a tiny / simple library</h2> |
| 17 |
|
| 18 |
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> |
| 19 |
|
| 20 |
<ins class="adsbygoogle" |
| 21 |
style="display:block" |
| 22 |
data-ad-client="ca-pub-7292810486004926" |
| 23 |
data-ad-slot="7806394673" |
| 24 |
data-ad-format="auto"></ins> |
| 25 |
<script> |
| 26 |
(adsbygoogle = window.adsbygoogle || []).push({}); |
| 27 |
</script> |
| 28 |
|
| 29 |
<h3>What ?</h3> |
| 30 |
<p> |
| 31 |
<strong>timeago.js</strong> is a tiny(2kb) library used to format date with `*** time ago`. eg: '3 hours ago'. No dependency. and support automatically updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago"). <a href="https://github.com/hustcc/timeago.js">Download</a>, view the examples, and enjoy. |
| 32 |
</p> |
| 33 |
|
| 34 |
<p class="example"> |
| 35 |
You opened this page <time class="need_to_be_rendered load_time strong">when you opened the page</time>. <span class="help">(This will update automatically. Wait for it.)</span> |
| 36 |
</p> |
| 37 |
<p class="example"> |
| 38 |
Hustcc was born <span class="need_to_be_rendered strong" datetime="1992-08-01">Aug 01, 1989</span>. |
| 39 |
</p> |
| 40 |
|
| 41 |
<h3>Why ?</h3> |
| 42 |
<p>timeago.js was built to format date with `*** time ago` statement. You can test timeago.js <a href="./demo.html">here</a> with the live demo.</p> |
| 43 |
<ul> |
| 44 |
<li>Avoid timestamps dated "1 minute ago" even though the page was opened 10 minutes ago; <em>timeago refreshes automatically</em>.</li> |
| 45 |
<li>You can <em>take full advantage of page caching</em> in your web applications, because the timestamps aren't calculated on the server.</li> |
| 46 |
<li>Very tiny(less than 2kb), and has <em>no dependency</em>, e.g. jQuery.</li> |
| 47 |
</ul> |
| 48 |
|
| 49 |
<h3>How ?</h3> |
| 50 |
<p class="how"> |
| 51 |
First, load and install <a href="https://github.com/hustcc/timeago.js">timeago.js</a> library: |
| 52 |
</p> |
| 53 |
<pre> |
| 54 |
npm install timeago.js</pre> |
| 55 |
<p class="how"> |
| 56 |
Load timeago.js library file with script tag: |
| 57 |
</p> |
| 58 |
<pre> |
| 59 |
<script src="dist/timeago.js" type="text/javascript"></script></pre> |
| 60 |
<p class="how"> |
| 61 |
Or you can use ES6 style: |
| 62 |
</p> |
| 63 |
<pre> |
| 64 |
import * as timeago from 'timeago.js';</pre> |
| 65 |
<p class="how"> |
| 66 |
Now, let's attach it to your timestamps on DOM ready: |
| 67 |
</p> |
| 68 |
<pre> |
| 69 |
timeago().render(document.querySelectorAll('.need_to_be_rendered'));</pre> |
| 70 |
<p class="how"> |
| 71 |
This will realtime render all <tt>selected</tt>(javascript DOM selector) elements with a class of <tt>need_to_be_rendered</tt>. |
| 72 |
</p> |
| 73 |
<pre> |
| 74 |
<span class="<em>need_to_be_rendered</em>" datetime="<em>2016-07-07T09:24:17Z</em>">July 07, 2016</span></pre> |
| 75 |
<p class="how"> |
| 76 |
You can also use it programmatically: |
| 77 |
</p> |
| 78 |
<pre> |
| 79 |
timeago.format(new Date()); //=> "<span id="demo_now"></span>" |
| 80 |
timeago.format('2016-09-07', 'zh_CN') //=> "<span id="demo_20160907"></span>" |
| 81 |
timeago.format(1473245023718); //=> "<span id="demo_timestamp"></span>"</pre> |
| 82 |
|
| 83 |
<h3>Locales register ?</h3> |
| 84 |
<p> |
| 85 |
Yes, timeago.js has locale/i18n/language support. Here are some <a href="https://github.com/hustcc/timeago.js/tree/master/src/lang">configuration examples</a>. Please submit a <a href="https://github.com/hustcc/timeago.js">GitHub pull request</a> for corrections or additional languages. |
| 86 |
</p> |
| 87 |
<pre> |
| 88 |
var locale = function(number, index, totalSec) { |
| 89 |
// number: the time ago / time in number; |
| 90 |
// index: the index of array below; |
| 91 |
// totalSec: total seconds between date to be formatted and today's date; |
| 92 |
return [ |
| 93 |
['just now', 'right now'], |
| 94 |
['%s seconds ago', 'in %s seconds'], |
| 95 |
['1 minute ago', 'in 1 minute'], |
| 96 |
['%s minutes ago', 'in %s minutes'], |
| 97 |
['1 hour ago', 'in 1 hour'], |
| 98 |
['%s hours ago', 'in %s hours'], |
| 99 |
['1 day ago', 'in 1 day'], |
| 100 |
['%s days ago', 'in %s days'], |
| 101 |
['1 week ago', 'in 1 week'], |
| 102 |
['%s weeks ago', 'in %s weeks'], |
| 103 |
['1 month ago', 'in 1 month'], |
| 104 |
['%s months ago', 'in %s months'], |
| 105 |
['1 year ago', 'in 1 year'], |
| 106 |
['%s years ago', 'in %s years'] |
| 107 |
][index]; |
| 108 |
}; |
| 109 |
timeago.register('pt_BR', locale); |
| 110 |
// then you can use it |
| 111 |
timeago.format(1473245023718, 'pt_BR');</pre> |
| 112 |
|
| 113 |
<h3>Where ?</h3> |
| 114 |
<p>Package is managed with npm. so <em>npm install timeago.js</em> will be the latest version.</p> |
| 115 |
<p> |
| 116 |
The code is hosted on |
| 117 |
GitHub: <a href="http://github.com/hustcc/timeago.js">http://github.com/hustcc/timeago.js</a>. |
| 118 |
Go on, live on the edge. |
| 119 |
</p> |
| 120 |
|
| 121 |
<h3>Who ?</h3> |
| 122 |
<p> |
| 123 |
timeago.js was built by <a href="https://atool.vip">Hustcc</a> while standing on the |
| 124 |
shoulders of giants. |
| 125 |
</p> |
| 126 |
|
| 127 |
<h3>What else ?</h3> |
| 128 |
<ul> |
| 129 |
<li><em>timeago.js for react</em>: timeago-react is <a href="https://github.com/hustcc/timeago-react">here</a></li> |
| 130 |
<li><em>timeago for python</em>: timeago is <a href="https://github.com/hustcc/timeago">here</a></li> |
| 131 |
</ul> |
| 132 |
<p class="example"> |
| 133 |
Other timeago, welcome to pull a request. |
| 134 |
</p> |
| 135 |
|
| 136 |
<h3>Do you use timeago.js ?</h3> |
| 137 |
<p> |
| 138 |
Great! Please let me know, and can add into the README</a>. |
| 139 |
</p> |
| 140 |
|
| 141 |
</div> |
| 142 |
<div id="footer"> |
| 143 |
Copyright © 2016 Theme from <a href="http://timeago.yarp.com/" target="_blank" rel="nofollow">jQuery-timeago</a>. |
| 144 |
Updated by <a href="http://Github.com/hustcc">Hustcc</a> |
| 145 |
</div> |
| 146 |
<script src="./timeago.min.js"></script> |
| 147 |
<script src="./index.js" type="text/javascript"></script> |
| 148 |
<script type="text/javascript"> |
| 149 |
init_index_page(); |
| 150 |
</script> |
| 151 |
<span style="display:none"> |
| 152 |
<script src="http://s4.cnzz.com/stat.php?id=1257060683&web_id=1257060683" language="JavaScript"></script> |
| 153 |
</span> |
| 154 |
</body> |
| 155 |
</html> |