JavaScript DHTML/Date Time/Date Extension — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 10:00, 26 мая 2010

Add user defined function method to Date object

  

<html>
<head>
  
  <script type="text/javascript">
    Date.prototype.getActualMonth = getActualMonth;
    function getActualMonth() {
      var n = this.getMonth();
      n += 1;
      return n;
    }
  </script>
</head>
<body>
<script type="text/javascript">
  var today = new Date();
  alert(today.getActualMonth());
</script>
</body>
</html>



Get calendar day in English

  

<html>
<head>
  
  <script type="text/javascript">
    Date.prototype.getCalendarDay = getCalendarDay;
    function getCalendarDay() {
      var n = this.getDay();
      var dow = new Array(7);
      dow[0] = "Sunday";
      dow[1] = "Monday";
      dow[2] = "Tuesday";
      dow[3] = "Wednesday";
      dow[4] = "Thursday";
      dow[5] = "Friday";
      dow[6] = "Saturday";
      return dow[n];
    }
  </script>
</head>
<body>
<script type="text/javascript">
  var today = new Date();
  alert(today.getCalendarDay());
</script>
</body>
</html>



Return actual month number

  

<html>
<head>
  
  <script type="text/javascript">
    Date.prototype.getActualMonth = getActualMonth;
    function getActualMonth() {
      var n = this.getMonth();
      n += 1;
      return n;
    }
  </script>
</head>
<body>
<script type="text/javascript">
  var today = new Date();
  alert(today.getActualMonth());
</script>
</body>
</html>



Return English name from date object

  

<html>
<head>
  
  <script type="text/javascript">
    Date.prototype.getCalendarMonth = getCalendarMonth;
    function getCalendarMonth() {
      var n = this.getMonth();
      var moy = new Array(12);
      moy[0] = "January";
      moy[1] = "February";
      moy[2] = "March";
      moy[3] = "April";
      moy[4] = "May";
      moy[5] = "June";
      moy[6] = "July";
      moy[7] = "August";
      moy[8] = "September";
      moy[9] = "October";
      moy[10] = "November";
      moy[11] = "December";
      return moy[n];
    }
  </script>
</head>
<body>
<script type="text/javascript">
  var today = new Date();
  alert(today.getCalendarMonth());
</script>
</body>
</html>



Return the actual day number from a date

  

<html>
<head>
  
  <script type="text/javascript">
    Date.prototype.getActualDay = getActualDay;
    function getActualDay() {
      var n = this.getDay();
      n += 1;
      return n;
    }
  </script>
</head>
<body>
<script type="text/javascript">
  var today = new Date();
  alert(today.getActualDay());
</script>
</body>
</html>