使用 jQuery 比较年和月 [英] Compare years and month with jQuery

查看:33
本文介绍了使用 jQuery 比较年和月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我该如何拆分和比较?在这个例子中是:

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

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

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

如果我只有月份和年份,比较两个日期的最佳方法是什么?

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

直播:http://jsfiddle.net/26zms/

推荐答案

像这样使用原生 Date 对象怎么样?

What about using the native Date object like this?

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

使用你的变量,它会产生ok".

With your variables it will yield "ok".

这篇关于使用 jQuery 比较年和月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆