jquery 格式化时间

/**
* 时间对象的格式化
*/
Date.prototype.format = function(format)
{
/*
* format="yyyy-MM-dd hh:mm:ss";
*/
var o = {
"M+" : this.getMonth() + 1,
"d+" : this.getDate(),
"h+" : this.getHours(),
"m+" : this.getMinutes(),
"s+" : this.getSeconds(),
"q+" : Math.floor((this.getMonth() + 3) / 3),
"S" : this.getMilliseconds()
}

if (/(y+)/.test(format))
{
format = format.replace(RegExp.$1, (this.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;
}

转自 http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html

jquery 格式化时间

时间: 2024-08-25 16:31:05

jquery 格式化时间的相关文章

jquery格式化时间

使用方法: new Date().format("yyyy-MM-dd hh:mm:ss"); 格式: Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, "d+": this.getDate(), "h+": this.getHours(), "m+": this.getMinutes(), &q

格式化时间 【js读书笔记】

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>格式化时间</title> </head> <body> <ul> <li>不写参数的时候,默认是格式化当前时间为YYYY-MM-DD hh:mm:ss格式,比如:<span class="t1

nodejs 模块moment格式化时间,获取当前时间的前一天时间

var moment = require('moment'); moment.locale('zh-cn'); var today = {}; var _today = moment(); today.year = _today.format('yyyy'); /*现在的年*/ today.date = _today.format('YYYY-MM-DD'); /*现在的时间*/ today.yesterday = _today.subtract(1, 'days').format('YYYY-

Java 格式化时间 不匹配

今天获取的时间不匹配,获取的时间是现在的时间,但是现实的时候确实 1970 年, 让我拍很郁闷! 应该讲 服务器返回的时间数据 * 1000 之后才进行,解析: Time 解析工具类: package com.hades.newstyle.utils; import java.text.DateFormat; import java.util.Date; /** * 传递一个时间, * 格式化时间的工具类: * * * @author Hades * @time Nov 4, 2014 * @t

php友好格式化时间

/** * 友好格式化时间 * @param int $timestamp 时间 * @param array $formats * @return string */ public static function formatDateTime($timestamp, $formats = null) { if ($formats == null) { $formats = array( 'DAY' => '%s天前', 'DAY_HOUR' => '%s天%s小时前', 'HOUR' =&g

OC中关于时间的几个函数及格式化时间

// // main.m // 时间格式化 // // Created by Macro on 14-12-10. // Copyright (c) 2014年 Macro. All rights reserved. // #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { //返回当前时间,以GMT为准 NSDate * date = [NSDate da

js 格式化时间日期函数小结

下面是脚本之家为大家整理的一些格式化时间日期的函数代码,需要的朋友可以参考下. 代码如下: Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, //month "d+" : this.getDate(), //day "h+" : this.getHours(), //hour "m+" : this.getMinutes(

格式化时间

格式化时间 by 伍雪颖 + (NSString *)formatTime:(NSString *)time { NSDateFormatter*dateFormatter =[[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"]; NSDate *date = [dateFormatter dateFromString:time]; [dateFormatte

Python time 获取格式化时间

Python中取得时间相关的信息的话,要用到python time模块,python time模块里面有很多非常好用的功能. Python中用time.time()取得当前时间的时间戳: >>> import time >>> print time.time() 1438608599.0 这里打印的时间是1970年到现在时间相隔的时间.这样一连串的数字不是我们想要的结果,我们可以利用time模块的格式化时间的方法来处理.用time.localtime()方法,作用是格式