//时间戳转换成指定格式的日期
DateTool.IntDatetimeTo = function(time, format)
{
    var testDate = new Date(time);
    var o =
    {
        "M+" : testDate.getMonth()+1,
        "d+" : testDate.getDate(),
        "h+" : testDate.getHours(),
        "m+" : testDate.getMinutes(),
        "s+" : testDate.getSeconds(),
        "q+" : Math.floor((testDate.getMonth()+3)/3),
        "S" : testDate.getMilliseconds()
    }
    if(/(y+)/.test(format))
    {
        format = format.replace(RegExp.$1, (testDate.getFullYear()+"").substr(4 - RegExp.$1.length));
    }
    for(var k in o)
    {
        if(new RegExp("("+ k +")").test(format))
        {
            format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
        }
    }
    return format;
}

javascript时间戳转换成指定格式的日期的更多相关文章

  1. javascript时间戳转换成yyyy-MM-DD格式

    最近开发中需要和后端进日期和时间传值,前后端约定为时间戳的格式,但是前端展示需要展示成年-月-日的格式.就需要进行日期和时间转换格式.自己总结两个方式就行转换. 一,new Date(时间戳).for ...

  2. javascript两行代码按指定格式输出日期时间

    javascript两行代码按指定格式输出日期时间,具体看代码: function date2str(x,y) { var z ={y:x.getFullYear(),M:x.getMonth()+1 ...

  3. js中时间戳转换成时间格式

    js中时间戳转换成时间格式, // 时间戳转换成时间格式 var formatDate = function(date){ date = new Date(date); var y=date.getF ...

  4. 把#define宏转换成指定格式

    之前在弄一个东西的,有一大堆的宏,需要把它转换成其它的形式.遇到这种大批量的东西,我特别没有耐心去一个一个的弄,于是写了一段代码. 估计大家平常比较难用得上,不过可以平常相似的情况用来参考. Sort ...

  5. jquery将日期转换成指定格式的字符串

    引用jquery文件,如<script type="text/javascript" src="jquery-1.8.3.min.js"></ ...

  6. js 时间戳转换成时间格式,可自定义格式

    由于 c# 通过ajax获取的时间 传到前台 格式为:/Date(1354116249000)/ 所以需要转换一下,想要什么格式 更改 format() 里的 返回语句 就可以了 formatDate ...

  7. php把时间戳转换成英文格式

    <?php echo "时间格式1:".date("Y-m-d H:i:s ")."<br>";// 2010-06-12 ...

  8. JAVA获取当前日期以及将字符串转成指定格式的日期

    /* * To change this template, choose Tools | Templates * and open the template in the editor. */ pac ...

  9. JS时间戳转换成时间格式

    TimeNow: function (val) { var date = new Date(val); var Y = date.getFullYear(); var m = date.getMont ...

随机推荐

  1. Educational Codeforces Round 27 F. Guards In The Storehouse

    F. Guards In The Storehouse time limit per test 1.5 seconds memory limit per test 512 megabytes inpu ...

  2. Mongodb搭建

    1.配置yum源,创建/etc/yum.repos.d/mongodb-org-3.2.repo文件,添加如下文件内容: [mongodb-org-3.2] name=MongoDB Reposito ...

  3. 启用nginx报错80端口被占用

    最近在本机跑nginx,启动后报错,怀疑80端口被占用 netstat -ano|findstr 尝试一:查看后发现端口被一个System pid 为4的一个程序占用.我在资源管理器中尝试将Syste ...

  4. 解决:Adb connection Error:远程主机强迫关闭了一个现有的连接

    最近刚入手了一台G12,用它来调试程序的时候,eclipse的console总是出现如下的错误“Adb connection Error:远程主机强迫关闭了一个现有的连接” 问题出现的原因:这是ddm ...

  5. DFS应用——查找强分支

    [0]README 0.1) 本文总结于 数据结构与算法分析, 源代码均为原创, 旨在 理解 "DFS应用--查找强分支" 的idea 并用源代码加以实现 : [1]查找强分支 1 ...

  6. Linux tar包安装Nginx

    1.首先安装依赖包(依赖包有点多.我们採用yum的方式来安装) yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel ...

  7. 要胀爆的Angular1.0

    尝试从http请求上遏制缓存: http://blog.csdn.net/u010039979/article/details/54376856 if (!$httpProvider.defaults ...

  8. Swift_4_闭包(Blocks)

    import Foundation println("Hello, World!") var arr = [1,2,4,6,74,2] func hasClosure(list:[ ...

  9. 关于iphone自动播放音频和视频问题的解决办法

    大家都知道 做移动端 会遇到音频和视频无法自动播放问题(我也遇到了)于是想办法解决这个问题 我只是找到了在微信中解决的办法(如果谁有在别的浏览器有这个办法  请私聊我 )我是没有发现 document ...

  10. 纯JS实现动态时间

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...