for Date

github: https://github.com/laixiangran/commonJS/blob/master/src/forDate.js

代码

/**
* Created by laixiangran on 2016/1/24
* homepage:http://www.cnblogs.com/laixiangran/
* for Date
*/ (function(undefined) { var com = window.COM = window.COM || {}; com.$DE = { // 求当前日期与传入的日期相隔多少天
getDateInterval: function(date) {
var d = new Date(date);
if (d == "Invalid Date") {
throw "Invalid Date";
}else {
// Math.abs 绝对值
return Math.abs(this*1-d*1)/60/60/1000/24;
}
}, // 求当前日期所在月的第一天
getFirstDateInMonth: function(date) {
return new Date(date.getFullYear(), date.getMonth(), 1);
}, // 求当前日期所在月的最后一天
getLastDateInMonth: function(date) {
return new Date(date.getFullYear(), date.getMonth()+1, 0);
}, // 求当前日期所在季度的第一天
getFirstDateInQuarter: function(date) {
return new Date(date.getFullYear(), Math.floor(date.getMonth()/3)*3, 1);
}, // 判断是否为闰年
isLeapYear: function(date) {
return new Date(date.getFullYear(), 2, 0).getDate() == 29;
}, // 求某年某月的天数
daysInMonth: function(year, month) {
var d = new Date();
d.setFullYear(year, (month == 12) ? 1 : month, 0);
return d.getDate();
}
};
}());

参考

http://www.cnblogs.com/rubylouvre/archive/2010/09/16/1827784.html

commonJS — 日期操作(for Date)的更多相关文章

  1. 日期操作类--Date类

    Date-API ava.util包提供了Date类来封装当前的日期和时间.Date类提供两个构造函数来实例化Date对象.第一个构造函数使用当前日期和时间来初始化对象. Date( ) 第二个构造函 ...

  2. PHP时间日期操作增减(date strtotime) 加一天 加一月

    date_default_timezone_set('PRC'); //默认时区 //当前的时间增加5天 $date1 = "2014-11-11"; echo date('Y-m ...

  3. JAVA笔记10__Math类、Random类、Arrays类/日期操作类/对象比较器/对象的克隆/二叉树

    /** * Math类.Random类.Arrays类:具体查JAVA手册...... */ public class Main { public static void main(String[] ...

  4. 菜鸡的Java笔记 日期操作类

    日期操作类        Date 类与 long 数据类型的转换        SimpleDateFormat 类的使用        Calendar 类的使用                如 ...

  5. Date日期操作

    获取年月日时分秒: package com.util; import java.text.DateFormat; import java.util.Calendar; import java.util ...

  6. java 字符串操作和日期操作

    一.字符串操作 创建字符串 String s2 = new String("Hello World"); String s1 = "Hello World"; ...

  7. JAVASE02-Unit03: 日期操作 、 集合框架

    Unit03: 日期操作 . 集合框架 java.util.Date package day03; import java.util.Date; /** * java.util.Date * Date ...

  8. Lua库之时间和日期操作

    Lua库之时间和日期操作 (2010-02-07 18:41:20) 转载▼ os.time() <== 返回当前系统的日历时间os.date() <== 返回本地化的时间字符串,这里是& ...

  9. 【转】JAVA 8 日期/时间(Date Time)API指南

    前言 本来想写下Java 8的日期/时间API,发现已经有篇不错的文章了,那就直接转载吧~ PS:主要内容没变,做了部分修改. 原文链接: journaldev 翻译: ImportNew.com - ...

随机推荐

  1. hibernate.properties

    hibernate.dialect=org.hibernate.dialect.MySQL5Dialect #hibernate.dialect=org.hibernate.dialect.Oracl ...

  2. python学习笔记五 模块下(基础篇)

    shevle 模块 扩展pickle模块... 1.潜在的陷进 >>> import shelve>>> s = shelve.open("nb" ...

  3. js 10秒钟倒计时

    第一个: <html> <head> <meta http-equiv="Content-Type" content="text/html; ...

  4. 在Visual Studio中使用MonoTouch开发iOS应用程序

    前段时间在工作机上装了Mac OS X,这主要是因为我最近需要开发iPhone应用程序.虽然Xcode,Objective C一定是开发iOS应用程序的主流,但是经过一番考虑,我还是决定尝试一下使用M ...

  5. CodeForces 651C Watchmen map

    Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn t ...

  6. 【leetcode❤python】Find the Difference

    #-*- coding: UTF-8 -*- class Solution(object):    def findTheDifference(self, s, t):                ...

  7. 登录界面 beta版

    1.MainActivity.java package com.example.administrator.myapplication; import android.content.Intent; ...

  8. Web开发, 跳转时出现java.lang.ClassNotFoundException

    发生这种状况一般都是由于类找不到,要么是web.xml没有配对位置,要么是类没有放好

  9. CA*Layer(CATransformLayer--CAGradientLayer)

    CATransformLayer CATransformLayer不同于普通的CALayer,因为它不能显示它自己的内容.只有当存在了一个能作用域子图层的变换它才真正存在.CATransformLay ...

  10. linux配置IP地址

    1. ifconfig命令临时配置IP地址 ifconfig命令:查看与配置网络状态命令 如:  ifconfig eht0 192.168.0.200 netmask 255.255.255.0 # ...