JavaScript Time Sensitive Actions

Simon Shahriveri 15th of March 2012

//set a function with various date related parameters
	function showBanner(startYear, startMonth, startDay, startHour, startMinute, endYear, endMonth, endDay, endHour, endMinute) {
		var currentDate = new Date();

		var startDate = new Date(Date.UTC(startYear, startMonth - 1, startDay, startHour, startMinute));
		var endDate = new Date(Date.UTC(endYear, endMonth - 1, endDay, endHour, endMinute));

		if (currentDate >= startDate && currentDate <= endDate) {
			return true;
		}

		return false;
	}

	$(document).ready(function() {

		// call our above function and run your chosen date and time parameters
		// e.g. the below reads: 2012, March, 15th at 12:40 - 2012, March 16th at 20:30 
		if (showBanner(2012, 3, 15, 12, 40, 2012, 3, 16, 20, 30)) {
			
			//do something that occurs between the above date/time selection

		} else {
			
			//do somethignthat appears outside the above date/time selection
		}
		
	});
268
Views
0
Comments
1
Downloads
Comments
Only Code Pad members can post comments!

Want to join Code Pad Request An Invite
    No Comments Posted

Suppo - Create, Customize & Host
Your App Support Page at Suppo

Snippet Details

  • Status: Public
  • Description: This snippet, allows you to set a 'from' and 'to' timeframe in which you will be able to perform time sensitive action. e.g. show a button on a website between a specific time frame and hide it after the time frame has completed.
  • Saved by: Simon Shahriveri
  • Type: jQuery
  • Date: 15th March 2012
  • Characters: 962
  • Views: 268
  • Likes: 2
  • Downloads: 1 (JavaScriptTimeSensitiveActions.txt)
Keyboard Shortcuts

DDownload

TTweet

FFull View

Next Snippet

Previous Snippet