Date object using JavaScript

Date object using JavaScript

What's the Date object using JavaScript?

View Answers

November 9, 2010 at 4:54 PM

Hi,

The Date object is used to work with dates and times. Date objects are created with the Date() constructor.

JavaScript has an inbuilt support for dates and times with its Date object. The methods of the Date object return various values associated with date and time.

To start working with dates and time, we first initialize a variable and assign it a value with the new operator and the Date() constructor. The main function of the new operator with Date() constructor is to create a new date object that is stored in the variable. Here is the code:

<script type="text/javascript">
<!--
var d = new Date();
var nhours=d.getHours();
var nmins=d.getMinutes();
var nsecn=d.getSeconds();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
document.write(curr_date + "-" + curr_month + "-" + curr_year);
document.write("<p>"+""+"</p>");
document.write( nhours+"-"+nmins+"-"+nsecn);
//-->
</script>









Related Tutorials/Questions & Answers:
Date object using JavaScript
Date object using JavaScript  What's the Date object using JavaScript
javascript date validation using regex
javascript date validation using regex  Hi, I want to validate the date using javascript. Please help.   <html> <head> <title>Validating Date format</title> <script type="text/javascript">
Advertisements
Display current date in text box in JSP using javascript
Display current date in text box in JSP using javascript In this section you will learn how to display current date in text box using JavaScript.For this purpose, we have used JavaScript Date object. The getDate() method returns the day
javascript date picker - Date Calendar
javascript date picker  how to insert a date picker user control in a html/jsp using javascript??? please help, it's urgent.  Hi Friend, Please visit the following links: http://www.roseindia.net/javascript
delete javascript object
delete javascript object  How to create and delete an object in JavaScript
JavaScript getMilliseconds method
JavaScript getMilliseconds method       JavaScript method getMilliseconds() returns the milliseconds value in the Date object using the local time.   ADS_TO_REPLACE_1  
create a new object in JavaScript
create a new object in JavaScript  How do you create a new object in JavaScript
create a new object in JavaScript
create a new object in JavaScript  How do you create a new object in JavaScript
javascript tomorrow date.
javascript tomorrow date.  Hi, how can I display tomorrow's date using javascript?   <html> <head> <title>Date after current date</title> <script type="text/javascript"> var mydate= new
JavaScript Show Date
, we are going to display the current date using JavaScript. You can see in the given example, we have created Date object which holds the current date and time... JavaScript Show Date
javascript date difference in years
javascript date difference in years  I want to find the difference between two dates with respect to years. I am using javascript. Please help.  ... with current day,date,time and GMT.you can also specify your own date by using new Date
javascript questions on date
javascript questions on date  how to add some days to an existing date
javascript date comparison
javascript date comparison  How to compare dates and display... language="JavaScript"> var date1 = new Date("jan, 25, 2010"); var today...,date,time and GMT.you can also specify your own date by using new Date(). You
javascript current date and time.
javascript current date and time.  How can we display current date and time using javascript?   <html> <head> <title>Current date and time</title> </head> <script type="text/javascript
javascript date difference in months
javascript date difference in months  How can I find the difference between two dates in terms of months using javascript?   <html> <head> <script type="text/javascript"> var date1=new Date(); var
javascript date difference in days.
javascript date difference in days.   I want to find the difference between two dates in terms of days. I am using javascript. Please help.  ...,date,time and GMT.you can also specify your own date by using new Date
javascript yesterday date.
javascript yesterday date.  Hi, How can I display the yesterday's... date</title> <script type="text/javascript"> var mydate= new Date...;/head> </html> Description: In javascript whenever you write new Date
Parsing into date object
Parsing into date object  Here is my code: String de = (String) session.getAttribute("licvalid"); DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); Date d=new Date(); out.println(d); Date toDt; int oneDay = 24*60*60*1000; toDt
Parsing into date object
Parsing into date object  Here is my code: String de = (String) session.getAttribute("licvalid"); DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); Date d=new Date(); out.println(d); Date toDt; int oneDay = 24*60*60*1000; toDt
JavaScript Validate UK Date
JavaScript Validate UK Date  How to Validate UK Date in JavaScript... if (!validformat.test(input.value)) alert('Invalid Date Format. Please correct.') else{ //Detailed check for valid date ranges var
date format in javascript
date format in javascript  display date format as dd/mm/yyyy and day... help me. thank u var date=/^\d{2}\/\d{2}\/\d{4}$/ if(document.userform.joindate.value.search(date)==-1) { alert("please enter date format as dd/mm/yyyy
JavaScript parse date
JavaScript parse date..., you will learn how to parse the date in JavaScript. JavaScript provides the function parse() that takes a date in string format and returns the equivalent
JavaScript getUTCDate method
; getUTCDate() method of JavaScript when applied to a date object returns an integer value between 1 and 31 that represents day from the date object's... "myDate". Now we can call the method getUTCDate() by using date object
JavaScript Date Difference
JavaScript Date Difference...; <h2>Date Difference</h2> <script type="text/javascript.... As you have already learnt about the JavaScript method Date.getTime
JavaScript setUTCDate method
; JavaScript setUTCDate() method when applied to a date object it sets... of the date object's month. In this part of JavaScript method tutorial we... getUTCDate() by using date object to show the current date and there after we
start date and end date validation in javascript - Ajax
start date and end date validation in javascript  hi, i am doing web surfing project. pls guide me for my project. i want start date and end validations in javascript. end date should be greater than start date if so less than
delete an entry using JavaScript
delete an entry using JavaScript  How to delete an entry using JavaScript
using for loop in javascript
using for loop in javascript  How to use for loop in JavaScript
Date Example
("Changed date object using setTime() method");         System.out.println... Changed date object using setTime() method Date...; In this section we are discussing about the specific date using the Date
JavaScript calendar date picker
a JavaScript Date object to a string, based on the dateFormat and dateSeparator... a string to a JavaScript Date object. */ function getFieldDate(dateString...: bold; } .style1 { color: #0000FF; } JavaScript calendar date
maximize an image using javaScript
maximize an image using javaScript  Write the code to maximize an image using javaScript
xls to js using javascript
xls to js using javascript  ![how can we convert a xls file in js file using javascript][1
timer using javascript
timer using javascript  How to display timer on HTML page using JavaScript
JavaScript setMonth() method
JavaScript setMonth() method       JavaScript setMonth() method is used to set month for the date object... a date object to call this method. Description of code :ADS_TO_REPLACE_2
send mail using JavaScript
send mail using JavaScript  How can we send mail using JavaScript?   Hi friends, You can not send email directly using JavaScript. But you can use JavaScript to execute a client side email program send the email using
Validating date in javascript - Java Interview Questions
Validating date in javascript   Hi Deepak, Can u give sample code validating date in javascript using text box. thank u in advance  In what format you are going to enter the date in Text box (i.e : dd/mm
JavaScript array object reference
that helps you in understanding JavaScript array object reference. For this we are using... JavaScript array object reference   ...;   Javascript_array_object_reference.htmlADS_TO_REPLACE_2 <
JavaScript setDate method
date by using date object "dt" and there after we will call setDate...; JavaScript setDate() method can be used to set a date value to the date..._TO_REPLACE_1  object_date.setDate(dateValue); Where object_date
How to shift and unshift using JavaScript?
How to shift and unshift using JavaScript?  How to shift and unshift using JavaScript
JavaScript Date Function
JavaScript Date Function Many language provide special functions for Date, JavaScript also provides many functions for it. Given examples will illustrate the functions. JavaScript Date Function Example:ADS_TO_REPLACE_1 <html>
Using POI - Date Calendar
Using POI  What can i do with POI in Java and also give me an example of it.Thanks
JavaScript setYear() method
of a date object. Syntax for using setYear() method is as follows: Syntax :ADS... is the object of date which is required to call setYear() method and the value passed...; } In above lines of code, first line of the function creates a date object
Java date to String, Convert date object into a string with a pattern
Convert date object into a string with a pattern This section illustrates you the conversion of date object into a string pattern. Java has provide many classes for formatting and parsing the date and time. Here we have used
getting current date without using system date - Date Calendar
getting current date without using system date  I want to get the current date but the Java code should not get System date as Current date. Pleae help me in getting current date without using system date. thanks in Advance
JavaScript exp method
JavaScript exp method       We can perform the mathematical calculations in the JavaScript by using the Math object reference. In Math object we have some very useful
read and write a file using javascript
read and write a file using javascript  How to read and write a file using javascript
checkboxes set to true using JavaScript
checkboxes set to true using JavaScript  To set all checkboxes to true using JavaScript
convert numbers to strings using JavaScript
convert numbers to strings using JavaScript  How to convert numbers to strings using JavaScript
Math Constants and Functions using JavaScript
Math Constants and Functions using JavaScript  What's Math Constants and Functions using JavaScript
associate functions with objects using JavaScript
associate functions with objects using JavaScript  How to associate functions with objects using JavaScript

Ads