JavaScript using Dates, JavaScript Tutorial, Global Guide Line Technology.
Bookmark Bookmark: JavaScript using Dates, JavaScript Tutorial Forum | Blog |

      Home                    

Basic JavaScript Guide.
 JScript Introduction.            
 JScript Why?                       
 JScript Recognitions.          
 JScript onMouseover.         
 JScript with Buttons.           
 JScript Alerts.                     
 JScript Variables.               
 JScript Operators.               
 JScript Functions.               
 JScript Prompts.                 
 JScript Conditions.             
 JScript Validations.            
 JScript Confirmation Boxes.
 JScript Browser Detection.  
 JScript Redirection.            
 JScript on Links.                 
 JScript Switch.                    
 JScript Loops.                     
 JScript Events.                    
 JScript Exception Handling.
 JScript Reserve Characters. 
 JScript with Objects.            
 JScript Math Object.           
 JScript using Dates.
 JScript using String.            
 JScript using Arrays.            
 JScript Operations.              
 JScript Handling Cookies.   
 JScript in Mapping.             
 JScript Time Out.                
 JScript Summary.                

JavaScript Tutorial >> JavaScript using Dates.


     Back             Next     


Date Object in JavaScript

In JavaScript Date class is used to store and retrieve dates information. To create a JavaScript Date object we can use any of the following techniques.

Syntax for Date Object in JavaScript

new Date ( )

Above line will create a new Date object with the value of the current date and time on that PC where the browser is running.. (We'll use this technique later on to display the current date on the page) First of all we need to store the date in a variable data:

var date = new Date ( );
Result will be :

Example of Date Object in JavaScript

<script language="javascript">
  var date=new Date();
  document.write(date);
</script>  

Methods to retrieve Date values in JavaScript

Following are the methods to extract information from the Date object: in JavaScript
 
Method  of Date object Description  of JavaScript Date Object Example of JavaScript Date
getFullYear () Retrieves the year component of the date as a 4-digit number. var x = new Date();
y = x.getFullYear ();
getMonth() getMonth() Function of Date Object retrieves the month component of the date as a number from 0 to 11 (0=January, 1=February, etc) var x = new Date();
y = x.getMonth()
getDate() getDate() Function of Date Object retrieves the day-of-month component of the date as a number from 1 to 31 var x = new Date();
y = x.getDate()
getDay() getDay() Function of Date Object retrieves the day of the week component of the date as a number from 0 to 6 (0=Sunday, 1=Monday, etc) var x = new Date();
y = x.getDay()
getHours() getHours() Function of Date Object retrieves the hours component of the date as a number from 0 to 23 var x = new Date();
y = x.getHours()
getMinutes() getMinutes() Function of Date Object retrieves the minutes component of the date as a number from 0 to 59 var x = new Date();
y = x.getMinutes()
getSeconds() getSeconds() Function of Date Object retrieves the seconds component of the date as a number from 0 to 59 var x = new Date();
y = x.getSeconds()
getMilliseconds() getMilliseconds() Function of Date Object retrieves the milliseconds component of the date as a number from 0 to 999 var x = new Date();
y = x.getMilliseconds()
getTimezoneOffset() getTimezoneOffset() Function of Date Object retrieves the time difference, in minutes, between the computer's local time and GMT var x = new Date();
y = x.getTimezoneOffset()

The above JavaScript Date methods are similar to the previous section of JavaScript Tutorial [JavaScript with Objects], but they work with UTC (Universal Time Coordinated) time, or GMT..  



     Back             Next     
 

JavaScript Date Object Functions and Properties Examples



[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright 2005 -  2018 www.globalguideline.com All rights reserved. (Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher) 182 visitors are online now