构造函数

new Date();
new Date(value);
new Date(dateString);
new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);

各参数的含义:

value 代表自1970年1月1日00:00:00 (世界标准时间) 起经过的毫秒数。
dateString 表示日期的字符串值。该字符串应该能被 Date.parse() 方法识别
year 代表年份的整数值。为了避免2000年问题最好指定4位数的年份; 使用 1998, 而不要用 98.
month 代表月份的整数值从0(1月)到11(12月)。
day 代表一个月中的第几天的整数值,从1开始。
hour 代表一天中的小时数的整数值 (24小时制)。
minute 分钟数。
second 秒数。
millisecond 表示时间的毫秒部分的整数值

当月第一天和最后一天

可直接用年月日构造一个日期:

var date = new Date(), y = date.getFullYear(), m = date.getMonth();
var firstDay = new Date(y, m, 1);
var lastDay = new Date(y, m + 1, 0);

var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);

指定月份的第一天和最后一天

比如2012年1月第一天和最后一天,运算时月份要减1

var y = 2012, m = 1
var firstDay = new Date(y, m - 1, 1);
var lastDay = new Date(y, m, 0);
console.log(firstDay);
console.log(lastDay);

参考地址:https://stackoverflow.com/questions/13571700/get-first-and-last-date-of-current-month-with-javascript-or-jquery?utm_source=ourjs.com

如果这篇文章对您有帮助,您可以打赏我

技术交流QQ群:15129679

js获取当月最后一天的更多相关文章

  1. php 日期 - 获取当月最后一天

    /** * 日期-获取当月最后一天 * @return int */ public function get_lastday() { if($this->month==2) { $lastday ...

  2. js获取本月最后一天

    function getLastDay() {      var seperator1 = "-";      var date=new Date;      var new_mo ...

  3. moment.js(moment-in-node.js)获取本月最后一天 不指定

    http://tommyhu.cn/moment-in-nodejs/ //获取本月最后一天 to=using.moment(日期).endOf('month').format("YYYY- ...

  4. golang 获取当月最后一天日期

    now := time.Now() year, month, day := now.Date() //fmt.Println(year, month, day) //2021 September 1 ...

  5. JS获取当月第一天和最后一天

    /** * 获取当前月的第一天 */function getCurrentMonthFirst(){ var date=new Date(); date.setDate(1); return date ...

  6. strtotime 获取当月最后一天的日期

    strtotime('last day of this month', $timestamp);

  7. JS获取当年当月最后一天日期

    <html xmlns="http://www.w3.org/1999/xhtml" > <meta charset="UTF-8"> ...

  8. 用js获取周、月第一天和最后一天(转载)

    var getCurrentWeek = function (day) { var days = ["周日", "周一", "周二", &q ...

  9. 关于JS获取某月最后一天

    发现网上用js获取某月最后一个的方式大多比较复杂,上个简单的: new Date(2013,4).toJSON().substring(0,10) new Date(2013,4,0).toLocal ...

随机推荐

  1. IAR EWAR 内联汇编 调用外部函数 Error[Og005], Error[Og006]

    How do I call a C function in another module from inline assembler in IAR EWARM? I have a bit of ass ...

  2. JS删除String里某个字符的方法

    关于JS删除String里的字符的方法,一般使用replace()方法.但是这个方法只会删除一次,如果需要将string里的所以字符都删除就要用到正则. 1 2 3 4 var str = " ...

  3. Access restriction: The method XXX from the type XXX is not accessible due to restriction XXX

    插件重构的时候 遇到这个问题 Access restriction: The method setDefaultAutoCommit(boolean) from the type BasicDataS ...

  4. Snmp学习总结(六)——linux下安装和配置SNMP

    一.安装SNMP 1.1.下载Net-SNMP的源代码 选择一个SNMP版本,比如5.7.1,下载地址如下:http://sourceforge.net/projects/net-snmp/files ...

  5. 交叉编译gdb和gdbserver

    从http://ftp.gnu.org/gnu/gdb/下载最新的gdb,我下载的是gdb-8.0. 编译aarch32(>armv5): #!/bin/bash export CC=arm-n ...

  6. springboot线程池的使用和扩展(转)

    springboot线程池的使用和扩展 我们常用ThreadPoolExecutor提供的线程池服务,springboot框架提供了@Async注解,帮助我们更方便的将业务逻辑提交到线程池中异步执行, ...

  7. Odoo8出现Internal Server Error的解决办法之一

    转载地址:http://blog.sina.com.cn/s/blog_7cb52fa80102vaf3.html     问题: 不知怎么回事,我的Odoo8出错了,重装也一样出错信息如下 Inte ...

  8. iOS7中的多任务 - Background Fetch,Silent Remote Notifications,Background Transfer Service

    转自:http://onevcat.com/2013/08/ios7-background-multitask/ 在IOS 7 出来不就,公司内部也组织了一次关于IOS 7 特性的的分享,今天看见on ...

  9. 玩android 遇到的问题-2014年1月15日

    1.变态的java工程,不是你点击run,它就run的.  eclipse 默认设置,你选择哪个文件,点击run的时候,就运行哪个文件.够变态不.那么,怎么设置点击run的时候,就运行整个工程呢? 你 ...

  10. 连接查询简析 join 、 left join 、 right join

    join :取两个表的合集: left join:左表的数据全部保留,然后增加右表与左表条件匹配的记录.如下 select cc.* from cloud_groups as cg left join ...