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