JSHelper时间格式化

Helper.prototype.FormatDate = function (format) {
    var _now = new Date();
    var o = {
        "M+": _now.getMonth() + 1, //month
        "d+": _now.getDate(), //day
        "h+": _now.getHours(), //hour
        "m+": _now.getMinutes(), //minute
        "s+": _now.getSeconds(), //second
        "q+": Math.floor((_now.getMonth() + 3) / 3), //quarter
        "S": _now.getMilliseconds() //millisecond
    }

    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (_now.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;
}
时间: 2024-07-30 03:26:42

JSHelper时间格式化的相关文章

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 toFix

jsp自定义标签(时间格式化包括Long转时间)

1.jsp自带标签的格式化: jstl fmt 函数大全:主要针对格式化功能 Tags   fmt:requestEncoding fmt:setLocale fmt:timeZone fmt:setTimeZone fmt:bundle fmt:setBundle fmt:message fmt:param fmt:formatNumber fmt:parseNumber fmt:formatDate fmt:parseDate 先在jsp页面上增加: <%@ taglib uri="h

js对特殊字符转义、时间格式化、获取URL参数

/*特殊字符转义*/ function replace_html(str) { var str = str.toString().replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"'); return str; } /* *时间格式化 *例子:time = new Date().Format(

iOS 获取当前时间格式化字符串

iOS 获取当前时间格式化字符串 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS.Android.Html5.Arduino.pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作. // 获取系统当前时间 NSDate * date = [NSDate date]; NSDateFormatt

Golang时间格式化

PHP中格式化时间很方便,只需要一个函数就搞定: date("Y-m-d H:i:s") 而在Golang中,用的是"2006-01-02 15:04:05"这样的layout string: time.Now().Format("2006-01-02 15:04:05") 2006表示year 01表示month 02表示day 15表示hour 04表示minute 05表示seconds 只能用以上这几个数字来格式化时间,假如把这里的200

String.Format,DateTime日期时间格式化集锦

DateTime dt = DateTime.Now;//2010年10月4日 17点05分 string str = ""; //str = string.Format("{0:y yy yyy yyyy}", dt); //10 10 2010 2010 //str = String.Format("{0:M MM MMM MMMM}", dt); //10 10 十月 十月 //str = String.Format("{0:d

PHP获取当前日期和时间格式化方法

使用函式 date() 实现 <?php echo $showtime=date("Y-m-d H:i:s");?> 显示的格式: 年-月-日 小时:分钟:妙 相关时间参数: a - "am" 或是 "pm" A - "AM" 或是 "PM" d - 几日,二位数字,若不足二位则前面补零; 如: "01" 至 "31" D - 星期几,三个英文字母; 如:

js时间格式化函数,支持Unix时间戳

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta charset="utf-8"> <title>js时间格式化函数,支持Unix时间戳</title> </head>

easyui的datetimebox时间格式化详解

今天公司让用easyui的datetimebox组件,而且还要让格式化成大家通用的那种,网上搜了很多,但差不多都是复制黏贴的,最后请教了下螃蟹. 感谢螃蟹抽空给做了个例子,现在拿出来和大家分享下,效果图如下这里主要实现了两个功能,一个是将时间格式化,一个是将年月日时分秒全都剥离了出来,可以随意调用. 具体的代码可到螃蟹博客主页看下,地址: http://www.itxxz.com/a/kuangjia/2014/0603/12.html easyui的datetimebox时间格式化详解,布布扣