JAVASCRIPT

 Home  Computers & Internet  Web Programming JAVASCRIPT
What is Javascript?
Javascript Placement
Syntax
Reserved Words
Variables
Data Types
Escaping Characters
Concatenation
Arithmetic Operators
Assignment Operators
Comparison Operators
Boolean Operators
Conditional Operator
If Statements
Else If Statements
If Else Statements
Switch Statements
While Loops
For Loops
Do While Loops
Break Statement
Continue Statement
prompt()
alert()
Date()
Event Handlers
String Object Methods
Math Object Methods
Window Object Methods
Arrays

JAVASCRIPT toString() METHOD

The toString() method in javascript converts a date object into date and time and returns the result as a string.

The general format is:

dateObject.toString(specified date[optional]);

The toString()method takes an optional specified date as parameter. If left out, today's date will be used.

If you want to return the full date/time with the toString()method, you will first have to create a new date object and then use the new date object with the toString()method.

Example 1: Return date/time string as of now.

<script type="text/javascript">

var dd = new Date(); //sets the date/time
document.write (dd.toString()); //outputs the date/time

</script>

Will output:



Example 2: Return date/time string with a specified date/time.

<script type="text/javascript">

var dd = new Date("May 21, 2007 01:15:00");
document.write (dd.toString());

</script>

Will output:



See Also:

getDate() getDay() getMonth()
getFullYear() getYear() getHours()
getMinutes() getSeconds() getTime()
getTimezoneOffset() parse() setDate()
setFullYear() setHours() setMinutes()
setMonth() setSeconds() setTime()
setYear() toGMTString() toLocaleString()
toString() getUTCDate() getUTCDay()
getUTCMonth() getUTCFullYear() getUTCHours()
getUTCMinutes() getUTCSeconds() getUTCMilliseconds()
setUTCDate() setUTCDay() setUTCMonth()
setUTCFullYear() setUTCHour() setUTCMinutes()
setUTCSeconds() setUTCMilliseconds()  
Home | Privacy Policy | Terms Of Use | Contact Us