Jquery time formatting plug-in and jquery formatting plug-in

Source: Internet
Author: User
Tags month name

Jquery time formatting plug-in and jquery formatting plug-in

 
Plug-in code: 
 
(Function ($) {$. formatDate = function (pattern, date) {// if not set, the default value is the current time if (! Date) date = new Date (); if (typeof (date) = "string") {if (date = "") date = new Date (); else date = new Date (date. replace (/-/g, "/");}/* fill 00 */var toFixedWidth = function (value) {var result = 100 + value; return result. toString (). substring (1) ;};/* configure */var options = {regeExp: /(yyyy | M + | d + | h + | m + | s + | ee + | ws? | P)/g, months: ['january ', 'february', 'march', '0000l', 'may', 'june', 'july ', 'August ', 'September', 'October ', 'November', 'december'], weeks: ['sunday', 'monday', 'tuesday', 'wednesday ', 'thursday', 'Friday', 'saturday']};/* time switching */var swithHours = function (hours) {return hours <12? "AM": "PM" ;};/* configuration value */var pattrnValue = {"yyyy": date. getFullYear (), // year "MM": toFixedWidth (date. getMonth () + 1), // month "dd": toFixedWidth (date. getDate (), // date "hh": toFixedWidth (date. getHours (), // Hour "mm": toFixedWidth (date. getMinutes (), // minute "ss": toFixedWidth (date. getSeconds (), // second "ee": options. months [date. getMonth ()], // month name "ws": options. weeks [date. getDay ()], // week name "M": date. getMonth () + 1, "d": date. getDate (), "h": date. getHours (), "m": date. getMinutes (), "s": date. getSeconds (), "p": swithHours (date. getHours ()}; return pattern. replace (options. regeExp, function () {return pattrnValue [arguments [0] ;};}) (jQuery );


Plug-in usage:

Premise to have a jquery-1.8.3.js

<! -- Use of jquery -->
<script type="text/javascript" src="jquery-1.8.3.js"/></script><script type="text/javascript" src="jquery.dateformat.js"></script><script type="text/javascript">$(function($){ var time = new Date("2014-01-01 13:20:30");  console.info($.formatDate("yyyy-MM-dd hh:mm:ss ws ee","2013-1-1 13:20:30"));});</script>


 

Effect:


Download Code Resources


Jquery formatting time

Convert js string type to time type:

Generally, the string is divided by space (), colon (:), and

Var dd = new Date ("1998", "11", "29", "10", "11", "44 ");

If the preceding format is used, convert it directly: var dd = new Date ("Tue, 09 Nov 2010 14:56:53 GMT ");

Jquery easyui datetimebox time format. After a time is selected, it is formatted as yyyy-MM-dd HH: mm: ss?

Jquery easyui provides a js file easyui-lang-zh_CN.js, imported in use, the default is this format, and many controls will default Chinese format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.