javascript - 使用 Sugar.js Javascript 获取当前月份

标签 javascript date

<!-- Date Range - Script  -->
<script>
$(function()
{

    // Set the default dates
    var startDate   = Date.create().addDays(-6),    // 7 days ago
        endDate     = Date.create();                // today

    var range = $('.range');

    // Show the dates in the range input
    range.val(startDate.format('{MM}/{dd}/{yyyy}') + ' - ' + endDate.format('{MM}/{dd}/{yyyy}'));

    range.daterangepicker
    ({
        startDate: startDate,
        endDate: endDate,
        ranges:
        {
            'This Month': [Date.create().addMonths(-1), 'today']
        }
    }
});
</script>

我正在使用sugar.min.js。我想获取从日期 1 到当前日期的当前月份。

This This Month': [Date.create().addMonths(-1), 'today'] 将为我提供 04/04/2014 的日期至 2014 年 5 月 4 日。我不想要上个月的日期,而是想要这个 05/01/2014 至 05/04/2014

最佳答案

sugar 的几个选项 manipulating dates文档:

Date.create().set({day: 1})
Date.create().beginningOfMonth()

关于javascript - 使用 Sugar.js Javascript 获取当前月份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23457188/

相关文章:

javascript - 使用 Jquery 同时将 html 和 text 设置为一个元素

javascript - 使用没有 sort() 方法的数字对数组进行排序

java - 使用 Java/Joda 的日期之间的周期

Excel 文件混合了日期作为文本和序列号

javascript - 从 Moment.js 的特定日期开始的几天/几周前

javascript - 将静态 map 保存为 Base64 图像? - map 探索

javascript - 为什么在定义带引号或不带引号的 JavaScript 对象文字时会有所不同?

javascript - jquery onclick无需滚动即可转到页面顶部

r - R 中的 Yearweek 解析错误

ruby - 有什么理由使用日期?