Dave Partner

Javascript tutorial - 29 - Date Object

  • 0 Replies
  • 154 Views

0 Members and 1 Guest are viewing this topic.

*

Offline Dave Partner

  • Administrator
  • Full Member
  • *****
  • 116
    • View Profile
Javascript tutorial - 29 - Date Object
« on: January 06, 2017, 06:13:45 AM »

<html>
   <head>
      <title></title>
      
   </head>
   <body>
      <script type="text/javascript" >
         /*
         Date Object
         
         JavaScript Date Formats
            A JavaScript date can be written as a string:


            String: Fri Jan 06 2017 05:06:15 GMT+0100 (W. Central Africa Standard Time)
            
            Number: 1,483,675,575,686
            
                Zero time : 01 January 1970 00:00:00 UTC.


         */
         
         
         
         
         //new Date
         var dateus = new Date(); //today's date
         document.write("<br/> Date() : " +dateus + "<br/>");
         
         //Zero Time
         var zerotime = new Date(86400000);
         document.write("<br/> Zero Time: "+zerotime + "<br/>");
         
         //Date from string
         var d = new Date("October 13, 2014 11:13:00");
         document.write("<br/> Date from string : " + d + "<br/>");
         
         //get date
         document.write("Get Date: "+ dateus.getDate() + "<br/>");
         document.write("Get Day: "+dateus.getDay() + "<br/>");
         
         document.write("Get Month: "+ dateus.getMonth() + "<br/>");
         document.write("Get Year: "+ dateus.getYear() + "<br/>");
         document.write("Get Time: "+ dateus.getTime() + "<br/>");
         
         //All dates
         //new Date(year, month, day, hours, minutes, seconds, milliseconds)
         var allDates = new Date(99, 5, 24, 11, 33, 30, 0);
         document.write("<br/> All Dates : "+allDates);
         
         
         
         
         
         /*
         
         Here is a list of the methods used with Date and their description.
Here is a list of the methods used with Date and their description.


Method   Description
Date()


Returns today's date and time
getDate()


Returns the day of the month for the specified date according to local time.
getDay()


Returns the day of the week for the specified date according to local time.
getFullYear()


Returns the year of the specified date according to local time.
getHours()


Returns the hour in the specified date according to local time.
getMilliseconds()


Returns the milliseconds in the specified date according to local time.
getMinutes()


Returns the minutes in the specified date according to local time.
getMonth()


Returns the month in the specified date according to local time.
getSeconds()


Returns the seconds in the specified date according to local time.
getTime()


Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC.
getTimezoneOffset()


Returns the time-zone offset in minutes for the current locale.
getUTCDate()


Returns the day (date) of the month in the specified date according to universal time.
getUTCDay()


Returns the day of the week in the specified date according to universal time.
getUTCFullYear()


Returns the year in the specified date according to universal time.
getUTCHours()


Returns the hours in the specified date according to universal time.
getUTCMilliseconds()


Returns the milliseconds in the specified date according to universal time.
getUTCMinutes()


Returns the minutes in the specified date according to universal time.
getUTCMonth()


Returns the month in the specified date according to universal time.
getUTCSeconds()


Returns the seconds in the specified date according to universal time.
getYear()


Deprecated - Returns the year in the specified date according to local time. Use getFullYear instead.
setDate()


Sets the day of the month for a specified date according to local time.
setFullYear()


Sets the full year for a specified date according to local time.
setHours()


Sets the hours for a specified date according to local time.
setMilliseconds()


Sets the milliseconds for a specified date according to local time.
setMinutes()


Sets the minutes for a specified date according to local time.
setMonth()


Sets the month for a specified date according to local time.
setSeconds()


Sets the seconds for a specified date according to local time.
setTime()


Sets the Date object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC.
setUTCDate()


Sets the day of the month for a specified date according to universal time.
setUTCFullYear()


Sets the full year for a specified date according to universal time.
setUTCHours()


Sets the hour for a specified date according to universal time.
setUTCMilliseconds()


Sets the milliseconds for a specified date according to universal time.
setUTCMinutes()


Sets the minutes for a specified date according to universal time.
setUTCMonth()


Sets the month for a specified date according to universal time.
setUTCSeconds()


Sets the seconds for a specified date according to universal time.
setYear()


Deprecated - Sets the year for a specified date according to local time. Use setFullYear instead.
toDateString()


Returns the "date" portion of the Date as a human-readable string.
toGMTString()


Deprecated - Converts a date to a string, using the Internet GMT conventions. Use toUTCString instead.
toLocaleDateString()


Returns the "date" portion of the Date as a string, using the current locale's conventions.
toLocaleFormat()


Converts a date to a string, using a format string.
toLocaleString()


Converts a date to a string, using the current locale's conventions.
toLocaleTimeString()


Returns the "time" portion of the Date as a string, using the current locale's conventions.
toSource()


Returns a string representing the source for an equivalent Date object; you can use this value to create a new object.
toString()


Returns a string representing the specified Date object.
toTimeString()


Returns the "time" portion of the Date as a human-readable string.
toUTCString()


Converts a date to a string, using the universal time convention.
valueOf()


Returns the primitive value of a Date object




         */
      </script>
      
      
      
   </body>
</html>