成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專欄INFORMATION COLUMN

timeago.js自動(dòng)將時(shí)間戳轉(zhuǎn)換為更易讀的時(shí)間格式

zhoutao / 2384人閱讀

timeago.js

timeago.js is a simple library (less than 2 kb) that is used to format datetime with *** time ago statement. eg: "3 hours ago".

Localization supported.

Time ago and time in supported.

Real-time render supported.

Nodejs and browserjs supported.

Well tested.

Official website. 中文版說明文檔點(diǎn)這里。 React version here: timeago-react. Python version here: timeago.

Such as

just now
12 seconds ago
3 minutes ago
2 hours ago
3 days ago
3 weeks ago
6 months ago
2 years ago

in 12 seconds
in 3 minutes
in 2 hours
in 24 days
in 6 months
in 2 years
1. Usage

1. Install timeago.js

npm install timeago.js

2. import timeago.js

ES6 style is supported, then get global object: timeago.

import timeago from "timeago.js";

// or

var timeago = require("timeago.js");

or link with script in html files:


3. Use class timeago

var timeagoInstance = new timeago();
timeagoInstance.format("2016-06-12");
2. Detailed Usage

1. Localization

Default locale is en, and the library supports en and zh_CN.

var timeagoInstance = new timeago();
timeagoInstance.format("2016-06-12", "zh_CN");

You can change the locale in the constructor or use the setLocale method;

var timeagoInstance = new timeago("zh_CN");
// or
new timeago().setLocale("zh_CN");

2. Set relative date

timeago is relative to the current date default. You can set it yourself.

var timeagoInstance = new timeago(null, "2016-06-10 12:12:12"); // set the relative date here.
timeagoInstance.format("2016-06-12", "zh_CN");

3. Use timestamp

new timeago().format(new Date().getTime() - 11 * 1000 * 60 * 60); // will get "11 hours ago"

4. Automatic rendering

HTML code:

js code

var timeagoInstance = new timeago();
// use render to render it in real time
timeagoInstance.render(document.querySelectorAll(".need_to_be_rendered"), "zh_CN");
// or cancel real-time render
timeagoInstance.cancel()

The input API render should be DOM object/array, pure javascript DOM node, and jQuery DOM object supported.

The API cancel will clear all the render timers and release all resources of the instance.

The DOM object should have the attribute datetime or data-timeago with date formated string.

5. Register local language

You can register your own language, this is a class static method. Like below, e.g.

// the local dict example is below.
var test_local_dict = function(number, index) {
  // number: the timeago / timein number;
  // index: the index of array below;
  return [
    ["just now", "a while"],
    ["%s seconds ago", "in %s seconds"],
    ["1 minute ago", "in 1 minute"],
    ["%s minutes ago", "in %s minutes"],
    ["1 hour ago", "in 1 hour"],
    ["%s hours ago", "in %s hours"],
    ["1 day ago", "in 1 day"],
    ["%s days ago", "in %s days"],
    ["1 week ago", "in 1 week"],
    ["%s weeks ago", "in %s weeks"],
    ["1 month ago", "in 1 month"],
    ["%s months ago", "in %s months"],
    ["1 year ago", "in 1 year"],
    ["%s years ago", "in %s years"]
  ][index];
};
// register your locale with timeago
timeago.register("test_local", test_local_dict);
// use the locale with timeago instance 
var timeagoInstance = new timeago();
timeagoInstance.format("2016-06-12", "test_local");

You can see locales dir for more locales.

Locale contributions are welcomed, thank you for submitting a GitHub pull request for corrections or additional languages. ^_^~

3. Contributions

The website is based on rmm5t/jquery-timeago which is a nice and featured project but depends on jQuery.

locale translations: The library needs more locale translations. You can:

Open an issue to write the locale translations, or submit a pull request. How to ? see en"s translation.

Please test the locale by exec npm test or node tests/locales_test.js. How to write testcase, see en"s test cases.

4. LICENSE

MIT

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://hztianpu.com/yun/90994.html

相關(guān)文章

  • 讓你的代碼更簡(jiǎn)短,更整潔,更讀的ES6小技巧

    摘要:讓你的代碼更簡(jiǎn)短,更整潔,更易讀的小技巧寫在文章前面這篇文章翻譯自文章就代碼整潔方面對(duì)進(jìn)行了總結(jié)。如果你正在使用的代碼使用的語法,這個(gè)是你需要注意的事情。更多還提供了我們很多很多其他的方式來使我們的代碼更簡(jiǎn)潔,更易讀,以及更穩(wěn)定。 讓你的代碼更簡(jiǎn)短,更整潔,更易讀的ES6小技巧 寫在文章前面 這篇文章翻譯自ES6 tips and tricks to make your code cl...

    wpw 評(píng)論0 收藏0
  • 也許是最簡(jiǎn)潔好用的timeago.js庫了

    摘要:地址項(xiàng)目主頁是一個(gè)非常簡(jiǎn)潔輕量級(jí)小于的很簡(jiǎn)潔的庫,用來將時(shí)間轉(zhuǎn)化成類似于時(shí)間前的描述字符串,例如小時(shí)前。 timeago.js Github地址:https://github.com/hustcc/timeago.js 項(xiàng)目主頁:http://timeago.org/ timeago.js 是一個(gè)非常簡(jiǎn)潔、輕量級(jí)、小于 2kb 的很簡(jiǎn)潔的Javascript庫,用來將datetime時(shí)...

    DataPipeline 評(píng)論0 收藏0
  • Python中的對(duì)日期時(shí)間的處理

    摘要:中提供了一個(gè)和的模塊可以用來做格式化日期和時(shí)間的。格式化日期通過模塊中方法來格式化日期函數(shù)接收時(shí)間元組并返回以可讀字符串表示薪資的時(shí)間格式的話由參數(shù)決定。每日寬度間隔為字符每行的長(zhǎng)度為是每星期的行數(shù)。 我們可以通過學(xué)習(xí)在Python中對(duì)日期時(shí)間的處理,可以在快速的完成工作,比如: 將日期時(shí)間作為日志信息的內(nèi)容輸入 計(jì)算某一個(gè)功能的執(zhí)行時(shí)間 用日期命名一個(gè)文件的名稱 記錄或者展示文件的...

    techstay 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

zhoutao

|高級(jí)講師

TA的文章

閱讀更多
最新活動(dòng)
閱讀需要支付1元查看
<