return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - Compare years and month with jQuery - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Compare years and month with jQuery - Stack Overflow

programmeradmin1浏览0评论
var onemonth = 3;
var oneyear = 2005;
var twomonth = 10;
var twoyear = 2000;

How can i split this and pare? In this example is:

var firstdate = onemonth + oneyear;
var seconddate = twomonth + twoyear;

if(firstdate < seconddate){
 alert('error');
}

How is the best method for pare two date if i have only month and year?

LIVE: /

var onemonth = 3;
var oneyear = 2005;
var twomonth = 10;
var twoyear = 2000;

How can i split this and pare? In this example is:

var firstdate = onemonth + oneyear;
var seconddate = twomonth + twoyear;

if(firstdate < seconddate){
 alert('error');
}

How is the best method for pare two date if i have only month and year?

LIVE: http://jsfiddle/26zms/

Share Improve this question asked Feb 21, 2012 at 15:20 Gryz OsheaGryz Oshea 3613 gold badges8 silver badges17 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 4

What about using the native Date object like this?

if (new Date(oneyear, onemonth) < new Date(twoyear, twomonth)){
  alert('error');
}else{
  alert('ok');
}

With your variables it will yield "ok".

Make then proper dates;

var firstdate =  new Date(oneyear, onemonth - 1, 1); 
var seconddate = new Date(twoyear, twomonth - 1, 1); 

Then the parison is valid (as opposed to paring arbitrarily created integers)

acording to me append zero and than concate string

var onemonth = 3; 
if(onemonth < 10)
 onemonth = "0" + onemonth;
var oneyear = 2005; 
var oneyearmonth = oneyear + onemonth; // 200503
var twomonth = 10; 
if(twomonth < 10)
 twomonth = "0" + twomonth ;
var twoyear = 2000;
var twoyearmonth = twoyear + twomonth ; //200010
if(oneyearmonth < twoyearmonth)
{
   alert("one month and year leass than tow month and year");
}

There's no need to use the Date object for this case. Simple math is sufficient:

  • Divide the month by twelve.
  • Add this value to the year.
  • Do the same for the other date(s), and pare the values:

Code:

var onemonth = 3;
var oneyear = 2005;
var twomonth = 10;
var twoyear = 2000;

var year1 = oneyear + onemonth / 12;
var year2 = twoyear + twomonth / 12;
if (year1 < year2) {
    // error?
}
发布评论

评论列表(0)

  1. 暂无评论