最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - getThirdMondayInJanuary(): Not working - Stack Overflow

programmeradmin3浏览0评论

I need to get third monday in january. I am trying this is javascript

**@guys who mented: I was trying to implement this.

  <script type="text/javascript">
  $(document).ready(function() {  
  $('#holidayDate').datepicker();  
  var availableTags = ["New years Day", "Martin Luther King Day", "Groundhog Day", "Valentine's Day", "Washington's Birthday",
"Easter", "Earth Day", "National Arbor Day", "Mother's Day", "Memorial Day", "Flag Day", "Father's Day", "Independence Day",
"Labor Day", "Columbus Day", "Halloween", "Veterans Day", "Thanksgiving Day", "Pearl Harbor Remembrance Day", "Christmas Day"];  
  $("#tags").autoplete({source:availableTags});  
  $('#holidayDate').change(function() {  
 var dateString = $(this).val().substring(0, 5); 
 var res = ""; 
 switch (dateString) { 
   case '01/01': res = availableTags[0]; break; 
   case getThirdMondayInJanuary(): res = availableTags[1]; break;
   case '02/02': res = availableTags[2]; break; 
   case '02/14': res = availableTags[3]; break; 
   case '04/22': res = availableTags[6]; break; 
   case '06/14': res = availableTags[10]; break; 
   case '07/04': res = availableTags[12]; break;
   case '10/31': res = availableTags[15]; break; 
   case '11/11': res = availableTags[16]; break; 
   case '12/07': res = availableTags[18]; break; 
   case '12/25': res = availableTags[19]; break;
  }        
  $('#tags').val(res);  
  });  
  });
  </script>      

I need to get third monday in january. I am trying this is javascript

**@guys who mented: I was trying to implement this.

  <script type="text/javascript">
  $(document).ready(function() {  
  $('#holidayDate').datepicker();  
  var availableTags = ["New years Day", "Martin Luther King Day", "Groundhog Day", "Valentine's Day", "Washington's Birthday",
"Easter", "Earth Day", "National Arbor Day", "Mother's Day", "Memorial Day", "Flag Day", "Father's Day", "Independence Day",
"Labor Day", "Columbus Day", "Halloween", "Veterans Day", "Thanksgiving Day", "Pearl Harbor Remembrance Day", "Christmas Day"];  
  $("#tags").autoplete({source:availableTags});  
  $('#holidayDate').change(function() {  
 var dateString = $(this).val().substring(0, 5); 
 var res = ""; 
 switch (dateString) { 
   case '01/01': res = availableTags[0]; break; 
   case getThirdMondayInJanuary(): res = availableTags[1]; break;
   case '02/02': res = availableTags[2]; break; 
   case '02/14': res = availableTags[3]; break; 
   case '04/22': res = availableTags[6]; break; 
   case '06/14': res = availableTags[10]; break; 
   case '07/04': res = availableTags[12]; break;
   case '10/31': res = availableTags[15]; break; 
   case '11/11': res = availableTags[16]; break; 
   case '12/07': res = availableTags[18]; break; 
   case '12/25': res = availableTags[19]; break;
  }        
  $('#tags').val(res);  
  });  
  });
  </script>      
Share Improve this question edited Jul 13, 2010 at 18:10 Some Java Guy asked Jul 13, 2010 at 17:52 Some Java GuySome Java Guy 5,11820 gold badges78 silver badges110 bronze badges 3
  • 4 Is getThirdMondayInJanuary actually implemented, or were you hoping the puter would do it for you? – Borealid Commented Jul 13, 2010 at 17:53
  • 3 I tried calling fixMyProgram(), but it didn't work. Do I need to call fixMyProgramPlease() instead? – JSBձոգչ Commented Jul 13, 2010 at 17:54
  • 2 I need money getMe1MillionDollars() is not working?? ;) – Janick Bernet Commented Jul 13, 2010 at 17:54
Add a ment  | 

4 Answers 4

Reset to default 11
  1. Change the colon to a semi-colon.
  2. Implement the method.

This question is so bad it isn't even funny. But at least you know how to ment so I am going to take a real shot at helping you.

Use this library: http://code.google./p/datejs/

Date().next().january().third().Monday();

http://www.google./search?sitesearch=www.w3schools.&as_q=getThirdMondayInJanuary

maybe if you changed your code to (not tested):

getThirdMondayInJanuary():  // this is working!

Here is a function to get the third Monday in January of any year as a Date:

function getThirdMondayInJanuary(year) {
  var jan1 = new Date(year, 0, 1), d = jan1.getDay();
  return new Date(year, 0, (d<2?16:23)-d);
}
发布评论

评论列表(0)

  1. 暂无评论