Saturday 14 July 2012

Moment.js




---------------------------------



<!-- <html>
  <head>
    <title>in a Moment.js</title>
  </head>

  <body>
    <h1>Moment.js here now: <span id="then" data-date="Sat Jul 14 2012 07:43:14 GMT-0400 (EDT)"></span></h1>
   
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="https://raw.github.com/timrwood/moment/1.6.2/moment.js"></script>
    <script>
      $(document).ready(function(){
        var then = $('#then'),
            date = moment(new Date(then.attr('data-date'))),
            update = function(){
                       then.html(date.fromNow());
                      };
       

        update();
        setInterval(update, 6000);
      });
    </script>
  </body>

</html>



 -->




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Formatting dates using the Moment.js date library</title>
</head>
<body>

    <p><time data-momentjs>2012-07-12</time></p>
    <p><time data-momentjs>1976-09-09</time></p>

    <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
    <script type="text/javascript" src="https://raw.github.com/timrwood/moment/1.1.1/moment.min.js"></script>
    <script type="text/javascript">
        jQuery(document).ready(function ($) {
            $("time[data-momentjs]").each(function (idx, item) {
                var $item = $(item),
                    mdate = moment($item.text(), "YYYY-MM-DD");
                $item.attr("title", mdate.format("ddd, MMM Do, YYYY")).text(mdate.fromNow());
            });
        });
    </script>

</body>
</html>



------------------------------ in a Moment.js

Moment.js here now:

Formatting dates using the Moment.js date library


No comments:

Post a Comment