Giter VIP home page Giter VIP logo

jquery.relativetime.js's Introduction

jquery.relativetime.js

将日期时间转换为几秒前,几分钟前,几小时前,几天前,几月前,几年前的jquery插件,超轻量级,只做转换这一件事情

日期时间格式 (Time format)

字符串时间:时间必须为24小时制,日期使用“-”分隔,例如:2016-02-28 23:49:03
时间戳:例如:1487830425

选择元素后直接转换 (Sample 1)

<!-- 字符串时间 -->
<div class="list-time">2016-02-28 23:49:03</div>
<div class="list-time">2016-08-28 23:49:03</div>
<!-- 时间戳 -->
<div class="list-time">1487830425</div>
<div class="list-time">1487820425</div>
<!-- 转换 -->
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.relativetime.js"></script>
<script type="text/javascript">
	$(".list-time").relativeTime();
</script>

传值返回转换后的结果 (Sample 2)

<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.relativetime.js"></script>
<script type="text/javascript">
/* 字符串时间 */
var timestr = $.relativeTime('2016-02-28 23:49:03');
console.log(timestr);
/* 时间戳 */       
var timestr = $.relativeTime(1487830425);
console.log(timestr);
</script>

自定义配置 (Sample 3)

$.relativeTime.options = {
    future : "in %s",
    past : "%s ago",
    ss : "seconds",
    ii : "%d minutes",
    hh : "%d hours",
    dd : "%d days",
    ww : "%d weeks",
    mm : "%d months",
    yy : "%d years"
};
var timestr = $.relativeTime('2016-02-28 23:49:03');
console.log(timestr);

jquery.relativetime.js's People

Contributors

onanying avatar

Stargazers

proguru avatar ruir avatar  avatar Liz S. avatar sunhao avatar  avatar indiboy avatar

Watchers

James Cloos avatar  avatar  avatar

jquery.relativetime.js's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.