Skip to main content link. Accesskey S
  • Anonymous
  • Log on
  • Help
  • IBM logo
  • Lotus Notes and Domino Application Development wiki
  • All Wikis
  • Home
  • Community Articles
  • Product Documentation
  • Learning Center


Search

Advanced Search

Categories

Tag Cloud

  • 6.0
  • 6.5
  • 8.0
  • 8.5
  • 8.5.1
  • 8.5.2
  • 8.5.3
  • action bar
  • Agents
  • Ajax
  • app dev
  • Application
  • beginner
  • C&S
  • calendaring and scheduling
  • client
  • composite applications
  • Controls
  • converters
  • css
  • Custom controls
  • Data Binding
  • db2
  • design elements
  • dialog boxes
  • Documents
  • Dojo
  • Domino
  • Domino Designer
  • Domino Designer 8.5
  • DXL
  • Eclipse
  • error handling
  • errors
  • extensions
  • FAQ
  • Forms
  • formulas
  • getting started
  • globalization
  • Help
  • html
  • Installation
  • interface
  • internationalization
  • iPhone
  • Java
  • JavaScript
  • localization
  • Lotus Domino Designer
  • LotusScript
  • LotusSphere
  • LotusTechInfo
  • menu bar
  • Mobile
  • new user
  • Notes
  • Notes 8
  • notes.ini
  • NSD
  • OpenNTF
  • partial update
  • performance
  • Pickers
  • Portal
  • presentations
  • programming
  • Redbooks
  • Requested Articles
  • roadmap
  • rooms and resources
  • samples
  • Scripting
  • security
  • tabs
  • templates
  • themes
  • Tips
  • toolbar
  • troubleshooting
  • tutorials
  • validation
  • variables
  • video
  • VideoFest
  • View
  • view control
  • ViewPanel
  • Views
  • web
  • Web apps
  • Web services
  • webdev
  • XML
  • Xpage
  • XPages
  • XPages Extensibility API
  • xsp-config
  • データソース
  • 九州地区ノーツパートナー会
InformationInformation
You are currently viewing machine translated content. IBM translation might be available. Click IBM Translated Product Documentation to see what is available.X


Home > JavaScript > Various Time Differences in JavaScript
Rate this article 1 starRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

Various Time Differences in JavaScript 

expanded Abstract
collapsed Abstract
No abstract provided.
ShowTable of Contents
HideTable of Contents
  • 1 Various Time Differences
    • 1.1 Usage

Various Time Differences

Find the difference in 2 date/times by day, hour, minutes and seconds.
 

  
/**
  * Get the time difference between 2 dates in days
  */
 function timeDayDifference(endDate,startDate) {
  var difference = endDate.getTime() - startDate.getTime(); 
  difference -= (Math.floor(difference/1000/60/60/24)*1000*60*60*24);
  return difference;
 }
 /**
  * Get the time difference between 2 dates in hours
  */
 function timeHourDifference(endDate,startDate) {
  var difference = endDate.getTime() - startDate.getTime();
  difference -= (Math.floor(difference/1000/60/60)*1000*60*60);
  return difference;
 }
 /**
  * Get the time difference between 2 dates in minutes
  */
 function timeMinuteDifference(endDate,startDate) {
  var difference = endDate.getTime() - startDate.getTime();
  difference -= (Math.floor(difference/1000/60)*1000*60);
  return difference;
 }
 /**
  * Get the time difference between 2 dates in seconds
  */
 function timeSecondDifference(endDate,startDate) {
  var difference = endDate.getTime() - startDate.getTime();
  difference = Math.floor(difference/1000);
  return difference;
 } 

 

Usage


 
 
var startDateTime = new Date(2010,5,10,8,0);
var endDateTime = new Date(2010,5,11,8,0); 
 
var dayDiff = timeDayDifference(endDateTime,startDateTime) ;
var hourDiff =  timeHourDifference(endDateTime,startDateTime);
var minDiff = timeMinuteDifference(endDateTime,startDateTime); 
var secDiff = timeSecondDifference(endDateTime,startDateTime); 
Visit keithstric.com for other Lotus Notes/Domino/XPage articles 


expanded Article information
collapsed Article information
Category:
JavaScript
Tags:
datetime

This Version: Version 17 March 24, 2010 11:42:35 AM by Keith Strickland  

expanded Attachments (0)
collapsed Attachments (0)

 


expanded Versions (17)
collapsed Versions (17)
Version Comparison     
Version Date Changed by               Summary of changes
This version (17) Mar 24, 2010 11:42:35 AM Keith Strickland  
16 Mar 24, 2010 11:13:50 AM Keith Strickland  
15 Mar 4, 2010 12:08:56 PM Keith Strickland  
14 Mar 4, 2010 12:08:07 PM Keith Strickland  
13 Mar 4, 2010 12:07:45 PM Keith Strickland  
12 Mar 4, 2010 12:06:35 PM Keith Strickland  
11 Mar 4, 2010 12:04:01 PM Keith Strickland  
10 Mar 4, 2010 12:02:29 PM Keith Strickland  
9 Mar 4, 2010 12:01:42 PM Keith Strickland  
8 Mar 4, 2010 12:00:25 PM Keith Strickland  
7 Mar 4, 2010 11:59:32 AM Keith Strickland  
6 Mar 4, 2010 11:58:28 AM Keith Strickland  
5 Mar 4, 2010 11:57:40 AM Keith Strickland  
4 Mar 4, 2010 11:53:34 AM Keith Strickland  
3 Mar 4, 2010 11:53:08 AM Keith Strickland  
2 Mar 4, 2010 11:51:12 AM Keith Strickland  
1 Mar 4, 2010 11:49:12 AM Keith Strickland  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedSubscribe to RSSHelpAbout
  • All Lotus and WebSphere Portal wikis
  • IBM developerWorks
  • IBM Software support
  • IBM Social Business User Experience Blog
  • IBMSocialBizUX on Twitter
  • IBMSocialBizUX on Facebook
  • Lotus product forums
  • IBM Social Business UX blog
  • IBM Collaboration Solutions
  • Recently added feedRecently added
  • Recently edited feedRecently edited
  • Recently added comments feedRecently Added Comments
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Contact IBM
  • IBM Terms of use
  • Wiki terms of use