//时间戳转换成指定格式的日期
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. nginx反向代理做cache配置

    前序:请耐性子看完,前面的这个配置可以达到按后缀名进行缓存,但无法被purge.后面的配置可以被purge.具体实施方案按个人情况而定. 需要第三方的ngx_cache_purge模块:wget ht ...

  2. linux 上安装apache 出现 configure: error: APR not found. Please read the documentation错误

    今日编译apache时出错: #./configure --prefix……检查编辑环境时出现: checking for APR... noconfigure: error: APR not fou ...

  3. unity回调函数范例

    using System.Collections; using System.Collections.Generic; using UnityEngine; public class callback ...

  4. @media screen 针对不同移动设备——响应式设计

    概念: device-pixel-ratio:定义输入设备屏幕的可视宽度与可见高度比率. device-width:输入设备屏幕的可视宽度. orientation :屏幕横竖屏定向.landscap ...

  5. jquery 通过属性选择器获取input不为disabled的对象

    $("input[id^='input_001']:not(:disabled)").each(function(){ console.log(this); });

  6. sgu 195 New Year Bonus Grant【简单贪心】

    链接: http://acm.sgu.ru/problem.php?contest=0&problem=195 http://acm.hust.edu.cn/vjudge/contest/vi ...

  7. 【python】-- pymsql 操作MySQL

    pymysql 对MySQL数据库进行简单数据操作python模块主要是:MySQLdb.pymsql,MySQLdb模块主要用于python2.X,而python3.X则使用pymsql,pymys ...

  8. Android笔记之使用Glide加载网络图片、下载图片

    Glide简介 不想说太多,真的很方便:P)可以节省我不少时间 GitHub地址:https://github.com/bumptech/glide 加载网络图片到ImageView Glide.wi ...

  9. cocos2dx的ui封装

    cocos2dx里加载cocosudio导出的ui配置文件,在这之上封装了一下,封装核心类包括 UIManager,UILayer,UIOwner UIManager是所有ui总的管理类,代码如下: ...

  10. linux 8 -- 管道组合Shell命令进行系统管理

    二十. 通过管道组合Shell命令获取系统运行数据: 1.  输出当前系统中占用内存最多的5条命令:     #1) 通过ps命令列出当前主机正在运行的所有进程.     #2) 按照第五个字段基于数 ...