reecefowell / jquery-timestamper
在JavaScript中创建模糊时间戳。
dev-master
2013-06-20 09:22 UTC
This package is not auto-updated.
Last update: 2024-09-23 14:02:41 UTC
README
关于
创建随时间自动更新的模糊时间戳。
作者:Reece Fowell <reece [at] codeconsortium [dot] com>
例如:1分钟前。3小时前。昨天17:50。
设置
要使用此插件,请将jQuery添加到您的网站。
此插件使用jQuery 1.7.1构建。
用法简单,将您的时间戳设置为缩写,如下所示
<abbr class="timestamper" title="2012-06-30 07:31">2012-06-30 at 07:31</abbr>
缩写的内容不重要,可以使用您喜欢的任何时间戳,但请注意,搜索引擎会缓存页面内容,因此请在该处输入合理的日期。
如果您想进行最小设置,类应该为timestamper,但可以进行更改。
标题必须符合YYYY-MM-DD HH:II日期格式,如果设置不正确,timestamper可能无法正常工作或产生奇怪的行为。
您可以选择自己的选择器和通过添加以下内容到HTML的head部分来更改CSS类。
<head> <script type="text/javascript"> $(document).ready(function() { $('abbr.timestamper').timestamper({ interval: (1000 * 60 * 5), }); }); </script> </head>
间隔是模糊时间戳更新频率。更改标签及其选择器在jQuery $('tag.class')部分。
完整配置
<head> <script type="text/javascript"> $(document).ready(function() { $('abbr.timestamper').timestamper({ interval: 10000, message: { just_now: 'less than a minute ago', min_1: '1 minute ago', min_x: '{IA} minutes ago', hour_1: '1 hour ago', hour_x: '{HA} hours ago', day_1: '{H}:{I} Yesterday', day_x: '{DA} days ago at {H}:{I}', }, seconds: { inMinute: 60, inHour: (60 * 60), inDay: (60 * 60 * 24), inWeek: (60 * 60 * 24 * 7), inMonth: (60 * 60 * 24 * 7 * 4), inYear: (60 * 60 * 24 * 365) } } }); </script> </head>