zoukankan      html  css  js  c++  java
  • js-时间戳转字符串


    function createTime(v){ var now = new Date(v); var yy = now.getFullYear(); // var mm = now.getMonth() + 1; // var dd = now.getDate(); // var hh = now.getHours(); // var ii = now.getMinutes(); // var ss = now.getSeconds(); // var clock = yy + "-"; if(mm < 10) clock += "0"; clock += mm + "-"; if(dd < 10) clock += "0"; clock += dd + " "; if(hh < 10) clock += "0"; clock += hh + ":"; if (ii < 10) clock += '0'; clock += ii + ":"; if (ss < 10) clock += '0'; clock += ss; return clock; }

     或者:

     /**************************************时间格式化处理************************************/
                 /*****************************createTime("yyyy-MM-dd hh:mm:ss",v)***v:时间戳**************************/
                 function createTime(fmt,v)   
                 { //author: zk  
                   var date = new Date(v);
                   var o = {   
                     "M+" : date.getMonth()+1,                 //月份   
                     "d+" : date.getDate(),                    //
                     "h+" : date.getHours(),                   //小时   
                     "m+" : date.getMinutes(),                 //
                     "s+" : date.getSeconds(),                 //
                     "q+" : Math.floor((date.getMonth()+3)/3), //季度   
                     "S"  : date.getMilliseconds()             //毫秒   
                   };   
                   if(/(y+)/.test(fmt))   
                     fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));   
                   for(var k in o)   
                     if(new RegExp("("+ k +")").test(fmt))   
                   fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
                   return fmt;   
                 }
              
  • 相关阅读:
    中国软件技术篇
    create pdf
    我来了
    补丁号
    rdlc里面用VB语法对数值型数据进行Format
    WinForm中有些控件不能添加ToolTip关联的解决方法
    javascript弹出对话框
    省市县关联菜单
    委托与事件
    ASP.NET多文件上传方案
  • 原文地址:https://www.cnblogs.com/zktww/p/10387888.html
Copyright © 2011-2022 走看看