Syntax
variableName = new Date();
variableName.methodName();
Method Name
|
Description
|
getDate() | Returns the day of the month (from 1-31) |
getDay() | Returns the day of the week (from 0-6) |
getMonth() | Returns the month (from 0-11) |
getYear() | Returns the year (four digits) |
getHours() | Returns the hour (from 0-23) |
getMinutes() | Returns the minutes (from 0-59) |
getSeconds() | Returns the seconds (from 0-59) |
getMilliseconds() | Returns the milliseconds (from 0-999) |
Example
<script language="JavaScript">
var d = new Date();
var output = "Today : " + d.getDate()+ "/";
output += (d.getMonth() + 1) + "/";
output += d.getYear() + " ";
output += d.getHours() + ":";
output += d.getMinutes() + ":";
output += d.getSeconds();
document.write(output);
</script>
figure 1: Example
If you want to show the day of the week such as Monday, Tuesday and etc.
You should using Array() because getDay() will return only a number.
##############################
Next Chapter >> JavaScript : Array Object
No comments:
Post a Comment