如何在两个日期之间获得一个月份 [英] How to get a no of months between Two dates

查看:84
本文介绍了如何在两个日期之间获得一个月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们......





i我正在为datepicker使用jquery插件。





这个我得到的月/日/年格式



所以我有2个文字日期的日期



Ex:



textfeild1:09/24/2012



textfeild1:12/25/2012



然后我想知道这两个日期之间没有月份





PLZ帮助我...为此我感到很沮丧更多的日子



谢谢&问候



Mallesh( emailid已删除

Hi friends...


i am using jquery plugin for datepicker.


in this i get month/day/year format

so i have 2 text feild for dates

Ex:

textfeild1: 09/24/2012

textfeild1: 12/25/2012

then i want to find out no of months between these 2 dates


plz help me... for this i am frustating from more days

Thanks & Regards

Mallesh(emailid deleted)

推荐答案

赞美这个答案

Compliments of This answer
//Set the two dates
var currentTime   = new Date()
var currDate      = currentTime.getMonth() + 1 + "/" + currentTime.getDate() + "/" + currentTime.getFullYear() //Todays Date - implement your own date here.
var iniPastedDate = "8/7/2012" //Pasted Date - Implement your own date here.

//currDate = 8/17/12 and iniPastedDate = 8/7/12

function DateDiff(date1, date2) {
    var datediff = date1.getTime() - date2.getTime(); //store the getTime diff - or +
    return (datediff / (24*60*60*1000)); //Convert values to -/+ days and return value      
}

//Write out the returning value should be using this example equal -10 which means 
//it has pasted by ten days. If its positive the date is coming +10.    
document.write (DateDiff(new Date(iniPastedDate),new Date(currDate))); //Print the results...



从这个答案中你唯一要做的就是获得月差值。


The only thing you have to do from this answer is to get the month diff value.


hi,



检查这些以下链接为您的答案。



如何在javascript中区分两个日期

javascript中两个日期之间的月份差异

如何在JavaScript中获得两个日期之间的区别?



谢谢


Check these following links for your answer.

How to get difference between two dates in javascript
Difference in months between two dates in javascript
How do I get the difference between two Dates in JavaScript?

Thanks


这篇关于如何在两个日期之间获得一个月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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