te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>jquery - how to check a date is within current week or current month or next month in javascript? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - how to check a date is within current week or current month or next month in javascript? - Stack Overflow

programmeradmin3浏览0评论

I have some friends' birthdays and want to separate them as follows :

  • birthdays which fall within the current week (within remaining days of current week starting from current day).
  • birthdays which fall within the current month (within remaining days of current month starting from current day).
  • birthdays which fall within the next month.

So all I want to know how to test each date in javascript to see if it falls within the remaining days of the current week/current month/next month.

N.B: say I have those dates in m/d/Y(06/29/1990) format.

Thanks

I have some friends' birthdays and want to separate them as follows :

  • birthdays which fall within the current week (within remaining days of current week starting from current day).
  • birthdays which fall within the current month (within remaining days of current month starting from current day).
  • birthdays which fall within the next month.

So all I want to know how to test each date in javascript to see if it falls within the remaining days of the current week/current month/next month.

N.B: say I have those dates in m/d/Y(06/29/1990) format.

Thanks

Share Improve this question edited Jul 9, 2012 at 10:11 Beetroot-Beetroot 18.1k3 gold badges39 silver badges44 bronze badges asked Jul 9, 2012 at 9:19 flyleafflyleaf 9954 gold badges11 silver badges28 bronze badges 1
  • 1 Parse the date then use the accessors of the Date object and pare the desired fields. – Denys Séguret Commented Jul 9, 2012 at 9:23
Add a ment  | 

2 Answers 2

Reset to default 8

Convert your date and current time to Date object and use it for parison. Some dry coding:

var now = new Date()
if (
   (check.getFullYear() == now.getFullYear()) &&
   (check.getMonth() == now.getMonth()) &&
   (check.getDate() >= now.getDate())
) {
   // remanining days in current month and today. Use > if you don't need today.
}

var nextMonth = now.getMonth() + 1
var nextYear = now.getFullYear()
if (nextMonth == 12) {
   nextMonth = 0
   nextYear++
}
if (
   (check.getFullYear() == nextYear) &&
   (check.getMonth() == nextMonth)
) {
   // any day in next month. Doesn't include current month remaining days.
}

var now = new Date()
now.setHours(12)
now.setMinutes(0)
now.setSeconds(0)
now.setMilliseconds(0)
var end_of_week = new Date(now.getTime() + (6 - now.getDay()) * 24*60*60*1000 )
end_of_week.setHours(23)
end_of_week.setMinutes(59)
end_of_week.setSeconds(59) // gee, bye-bye leap second
if ( check >=now && check <= end_of_week) {
   // between now and end of week
}

the code Using the Parse Date is

var selecteddate = '07/29/1990';
var datestr = selecteddate.split('/');

var month = datestr[0];
var day = datestr[1]; 
var year = datestr[2];

var currentdate = new Date();
var cur_month = currentdate.getMonth() + 1;
var cur_day =currentdate.getDate();
var cur_year =currentdate.getFullYear();

if(cur_month==month && day >= cur_day)
{
 alert("in this month");
}

   else
   {
  alert("not in this month");
   }    ​
发布评论

评论列表(0)

  1. 暂无评论