JavaScript DHTML/Date Time/Date Extension

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

Add user defined function method to Date object

   <source lang="html4strict">
 

<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>


 </source>
   
  


Get calendar day in English

   <source lang="html4strict">
 

<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>


 </source>
   
  


Return actual month number

   <source lang="html4strict">
 

<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>


 </source>
   
  


Return English name from date object

   <source lang="html4strict">
 

<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>


 </source>
   
  


Return the actual day number from a date

   <source lang="html4strict">
 

<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>


 </source>