The Better Website Blog

Jun 02 2010

For Developers: jQuery Date Formatting Plugins

Posted by Michael Gilley | June 2nd, 2010

Dear Developers.  180byDesign has a freebie giveaway for you here.

We just created a couple of jQuery plugins in order to format dates a little easier.  Enjoy!

jDate Plugin for jQuery
This is an easy plugin that is ported from Php.js’ date() function. Basically, it mimics php’s date function taking two parameters (date format string, timestamp in seconds) with the first being the only one required. This plugin features a jQuery function for easy returns of formatted date strings as well as the convenience of a jQuery method that inserts the formatted date string into each matched element as text. If you need help with the function just follow the guidelines at php’s documentation site here. Here are some examples of use:

$.date(string format [, int timestamp]);

Examples:
$.date(‘F j, Y \\a\\t g:i:sa’);  will return =>  “January 1, 1970 at 12:00am”
$(’.date’).date(‘Y-m-d H:i:s’);  will insert the string into .date => <div class=“date”>1970-01-01 12:00:00</div>
$.date(‘m/d/Y’, 127018165); will return => “01/09/1974”

Download: jDate.plugin.tgz

jStrtostring Plugin for jQuery
Like it’s big brother, jDate, this plugin is a port from php.js’ strtotime() function. It acts just like the strtotime function in php taking two parameters with only the first required. It is used as follows:

$.strtotime(string time [, int now]);

Examples:
$.strtotime(’+3 weeks’); => timestamp in seconds exactly three weeks in the future
$.strtotime(’-1 year 2 days 7 hours’);
$.strtotime(‘now’);
$.strtotime(‘last Monday’);

Used in conjunction with jDate above:
$.date(‘F j, Y’, $.strtotime(’+30 minutes’));

Download: jStrtotime.plugin.tgz

About the Author: Michael Gilley

Comments (1)

  1. by Weblog says:

    Frank Zappa~ Rock journalism is people who cant write interviewing people who cant talk for people who cant read.
     
    - http://generating-mlm-leads.blogspot.com/

Respond:

Remember my personal information
Notify me of follow-up comments?