jquery時間格式化外掛程式,jquery格式化外掛程式

來源:互聯網
上載者:User

jquery時間格式化外掛程式,jquery格式化外掛程式

外掛程式的代碼:

(function($){$.formatDate = function(pattern,date){//如果不設定,預設為目前時間if(!date) date = new Date();if(typeof(date) ==="string"){ if(date=="")  date = new Date();  else  date = new Date(date.replace(/-/g,"/"));}/*補00*/var toFixedWidth = function(value){ var result = 100+value; return result.toString().substring(1);};/*配置*/var options = {regeExp:/(yyyy|M+|d+|h+|m+|s+|ee+|ws?|p)/g,months: ['January','February','March','April','May',         'June','July', 'August','September',  'October','November','December'],weeks: ['Sunday','Monday','Tuesday',        'Wednesday','Thursday','Friday','Saturday']};/*時間切換*/var swithHours = function(hours){return hours<12?"AM":"PM";};/*配置值*/var pattrnValue = {"yyyy":date.getFullYear(),                      //年份"MM":toFixedWidth(date.getMonth()+1),           //月份"dd":toFixedWidth(date.getDate()),              //日期"hh":toFixedWidth(date.getHours()),             //小時"mm":toFixedWidth(date.getMinutes()),           //分鐘"ss":toFixedWidth(date.getSeconds()),           //秒"ee":options.months[date.getMonth()],           //月份名稱"ws":options.weeks[date.getDay()],              //星期名稱"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);


外掛程式使用:

前提要有一個jquery-1.8.3.js

<!-- 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>




效果:


代碼資源下載


jquery 格式化時間

js 字串類型轉換成時間類型:

一般是根據空格( ),冒號(:)分割字串,然後

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

如果是上面的格式,直接轉化即可: var dd=new Date("Tue, 09 Nov 2010 14:56:53 GMT");
 
jquery easyui datetimebox時間格式化,當選中一個時間後格式化成yyyy-MM-dd HH:mm:ss這種格式的?

jquery easyui 提供了一個js檔案easyui-lang-zh_CN.js,在使用時匯入,預設就是這種格式,而且很多控制項都會預設中文格式
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.