[timeagoライブラリ] 経過時間、日時を表示する

説明

timeagoライブラリで経過時間、日時を表示するにはabbrタグにスタイルシートクラス名timeago、title属性に基準年月日&日時を指定します。時間は指定しなくても動作します。ページが読み込まれたら$("abbr.timeago").timeago()とすれば経過日数などが表示されます。日本語で表示したい場合にはライブラリの先頭部分にある英文を変更してください。

サンプルプログラム

【HTML】
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Sample</title>
<link rel="stylesheet" href="css/jquery.clearableTextField.css" type="text/css" media="all" />
<link rel="stylesheet" href="css/main.css" type="text/css" media="all" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.timeago.js"></script>
<script type="text/javascript" src="js/sample.js"></script>
</head>
<body>
<h1>xx年前のように表示する</h1>
2009年1月1日から<abbr class="timeago" title="2009-1-1"></abbr>経過しました。
</body>
</html>

【sample.js】
$(function(){
$("abbr.timeago").timeago();
});
サンプルを実行
[戻る]