Payament
Free Photos
WordPress Themes

JavaScript Time Sensitive Actions

//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 } });
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.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.