<!-- 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/