//重写toString方法,将时间转换为Y-m-d H:i:s格式
Date.prototype.toString = function(){
return this.getFullYear() + "-" + (this.getMonth()+) + "-" + this.getDate() + " " + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds();
}
//格式化时间字符串
Date.prototype.toFormatString = function(format){
if(format == ""){
return this.toString();
}
var str = '';
str = format.replace(/Y|y/,this.getFullYear())
.replace(/M|m/,this.getMonth() + )
.replace(/D|d/,this.getDate())
.replace(/H|h/,this.getHours())
.replace(/I|i/,this.getMinutes())
.replace(/S|s/,this.getSeconds());
return str;
}
//在当前时间上添加年数
Date.prototype.addYear = function(years){
var cyear = this.getFullYear();
cyear += years;
this.setYear(cyear);
return this;
}
//在当前时间上添加天数
Date.prototype.addDay = function(days){
var cd = this.getDate();
cd += days;
this.setDate(cd);
return this;
}
//在当前时间上添加月数
Date.prototype.addMonth = function(months){
var cm = this.getMonth();
cm += months;
this.setMonth(cm);
return this;
}

js日期 操作的更多相关文章

  1. js中时间戳与日期转换-js日期操作

    常用的一些日期操作. 用js获取一个时间戳. <script type="text/javascript"> var date = new Date();//当前时间 ...

  2. js日期操作

    1.最基本的日期操作 var mydate = new Date(); set/get   FullYear,Month,Date,Hour,Minutes,Second可以随意拼接 toLocale ...

  3. Js 日期操作

    Js获取当前日期时间及其它操作var myDate = new Date();myDate.getYear();        //获取当前年份(2位)myDate.getFullYear();    ...

  4. js moment.js日期操作类 datetime,日期操作,dayjs

    http://momentjs.com/ JS时间处理插件MomentJS https://juejin.im/post/5a2bdc55f265da432b4abf5e Day.js 2kB超轻量时 ...

  5. JS 日期操作类

    /* 日期对象格式化为指定日期格式 */Date.prototype.format = function (format) { var o = { "M+": this.getMo ...

  6. js日期操作,某天的N天后,一个月后的日期

    var date = new Date(); var tomorrow = date.setDate(new Date().getDate() + 10); //10天后的日期 console.log ...

  7. JS 日期工具类-基于yDate

    源码下载 前言:最近在用到JS日期操作时,发现有一些不方便,于是搜素了一些网上的资料,基于一个开源工具类-yDate 进行了个性化定制,封装成了一个日期工具类工具函数大概介绍:1.普通的日期操作2. ...

  8. JS常见操作,日期操作,字符串操作,表单验证等

    复制代码 //第一篇博文,希望大家多多支持 /***** BasePage.js 公共的 脚本文件 部分方法需引用jquery库 *****/ //#region 日期操作 //字符串转化为时间. f ...

  9. Js 日期选择,可以的一个页面中重复使用本JS日历,兼容IE及火狐等主流浏览器,而且界面简洁、美观,操作体验也不错。

    <html> <head> <title>Js日期选择器并自动加入到输入框中</title> <meta http-equiv="con ...

随机推荐

  1. SPOJLCS Longest Common Substring

    题意 A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is th ...

  2. 缓存(Cache)管理 ---- 系列文章

    利用Cache防止同一帐号重复登录 .net中Cache管理操作 系统缓存全解析 (下) 系统缓存全解析 (中) 系统缓存全解析 (上) 出处:http://www.cnblogs.com/luckd ...

  3. 7天学会HTML-Day01

    HTML初步 关键词: B/S C/S .服务器访问原理.标签.html特性.列表.图片 1.B/S 和C/S 架构 B/S -> browser/server 浏览器服务器架构 C/S -&g ...

  4. mysql字段详细

    http://www.runoob.com/mysql/mysql-data-types.html

  5. FPGA前世今生(三)

    上期介绍了关于FPGA的IOB单元,这期我们介绍一下FPGA内部的其他资源,这些都是学好FPGA的基础.不管前世的沧桑,还是后世的风光,我们都要把我现在的时光,打好基础,学好FPGA. 大多数FPGA ...

  6. java显示网格————————

    总结:看图 +---+---+ | | | | | | +---+---+ */ package com.aaa; //在屏幕上显如下网格 public class adga { public sta ...

  7. 分布式缓存系统 Memcached 基本配置与命令

    为了方便测试,给出一个C客户端libmemcached链接:https://launchpad.net/libmemcached/ 以及memcacheclient-2.0 : http://code ...

  8. zabbix的sendEmail配置

    zabbix的sendEmail配置 [root@hongquan scripts]# yum install sendmail[root@hongquan soft]# tar xvzf sendE ...

  9. php命令执行

    php命令执行通过函来执行外部应用程序,函数有shell_exec(),exec(),system(),passthru() <?php $i = $_GET['cmd']; echo exec ...

  10. rpm --import /etc/pki/rpm-gpg/RPM* 有什么用?

      今天用yum安装软件,遇到了Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL问题,为了加深印象,特别搜索了RPM-GPG-K ...