Code Monkey home page Code Monkey logo

prettydate's Introduction

Pretty Date

A jQuery date prettify plugin.

Main

dist/
├── prettydate.js      (9 KB)
└── prettydate.min.js  (4 KB)

Getting started

Installation

Include files:

<script src="/path/to/jquery.js"></script><!-- jQuery is required -->
<script src="/path/to/prettydate.js"></script>

Usage

Initialize with prettydate attribute

Basic

<span prettydate>Jan 01 2014 20:14:11</span>

Add options with data-* attribute

<span prettydate data-date-format="YYYY.M.D h:m:s">2014.1.1 20:14:11</span>

Initialize with $.fn.prettydate method

Basic

<span class="prettydate">Jan 01 2014 20:14:11</span>
$(".prettydate").prettydate();

Add options

<span class="prettydate"></span>
$(".prettydate").prettydate({
    date: "01/01/2014 20:14:11",
    dateFormat: "MM/DD/YYYY hh:mm:ss"
});

Configure

Setup

Setup with $("#target").prettydate(options), or global setup with $.fn.prettydate.setDefaults(options).

Options

afterSuffix

  • type: string
  • default: "later"

beforeSuffix

  • type: string
  • default: "ago"

autoUpdate

  • type: boolean
  • default: false

Auto update the pretty date string.

date

  • type: object / number / string
  • default: null

The target date for prettify. Allow date object, date number (milliseconds), valid date string, or custom date string with a date format.

dateFormat

  • type: string
  • default: "YYYY-MM-DD hh:mm:ss"

"Y" for year, "M" for month, "D" for day, "h" for hour, "m" for minute, "s" for second.

duration

  • type: number
  • default: 60000

The duration milliseconds of the auto update action.

messages

  • type: object
  • default:
{
    second: "Just now",
    seconds: "%s seconds %s",
    minute: "One minute %s",
    minutes: "%s minutes %s",
    hour: "One hour %s",
    hours: "%s hours %s",
    day: "One day %s",
    days: "%s days %s",
    week: "One week %s",
    weeks: "%s weeks %s",
    month: "One month %s",
    months: "%s months %s",
    year: "One year %s",
    years: "%s years %s",

    // Extra
    yesterday: "Yesterday",
    beforeYesterday: "The day before yesterday",
    tomorrow: "Tomorrow",
    afterTomorrow: "The day after tomorrow"
}

For each message, the first "%s" placeholder will be replaced with the date difference number, and the second "%s" placeholder will be replaced with the before or after suffix.

Methods

prettify

  • Prettify and replace the date again.
  • Usage: $("#target").prettydate("prettify").

destroy

  • Destroy the prettydate instance from the element.
  • Usage: $("#target").prettydate("destroy").

Browser Support

  • IE 6+
  • Chrome 33+
  • Firefox 27+
  • Safari 5.1+
  • Opera 19+

As a jQuery plugin, you can reference to the jQuery Browser Support.

License

Released under the MIT license.

prettydate's People

Contributors

lucasnevesaraujo avatar

Watchers

 avatar  avatar

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.