打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
js日期格式化
 function Window_Load(){
        var str = "Tue Jul 16 01:07:00 CST 2013";
        alert(formatCSTDate(str,"yyyy-M-d hh:mm:ss")); //2013-7-16 16:24:58
         
        alert(formatDate((new Date()),"yyyy-MM-dd")); //2013-07-15 
        alert(formatDate((new Date()),"yyyy/M/d")); //2013/7/15 
      
       
      //格式化CST日期的字串
      function formatCSTDate(strDate,format){
        return formatDate(new Date(strDate),format);
      }
       
      //格式化日期,
      function formatDate(date,format){
        var paddNum = function(num){
          num += "";
          return num.replace(/^(\d)$/,"0$1");
        }
        //指定格式字符
        var cfg = {
           yyyy : date.getFullYear() //年 : 4位
          ,yy : date.getFullYear().toString().substring(2)//年 : 2位
          ,M  : date.getMonth() + 1  //月 : 如果1位的时候不补0
          ,MM : paddNum(date.getMonth() + 1) //月 : 如果1位的时候补0
          ,d  : date.getDate()   //日 : 如果1位的时候不补0
          ,dd : paddNum(date.getDate())//日 : 如果1位的时候补0
          ,hh : date.getHours()  //时
          ,mm : date.getMinutes() //分
          ,ss : date.getSeconds() //秒
        }
        format || (format = "yyyy-MM-dd hh:mm:ss");
        return format.replace(/([a-z])(\1)*/ig,function(m){return cfg[m];});
      

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
JavaScript 中如何将日期格式化为 DD/MM/YYYY
SimpleDateFormat 造成的时间浪费
jstl 格式化时间,数字方法集合
js Date格式化为yyyy-mm-dd类字符串
Hive sql常用函数
jQuery EasyUI自定义DataGrid的Editor
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服