menghitung umur
reset tanggal
align image
Some text. Some text. Some text. Some text.
last modified
This document was last modified on:
Note: The lastModified property only works in Internet Explorer and Firefox.
Hari dan komentar
This JavaScript will generate a different greeting based on what day it is. Note that Sunday=0, Monday=1, Tuesday=2, etc.
alert
confirm box
prompt box
alert with linebreak
loop (pengetikan ulang)
Explanation:
This for loop starts with i=0.
As long as i is less than, or equal to 5, the loop will continue to run.
i will increase by 1 each time the loop runs.
loop lagiExplanation:
i is equal to 0.
While i is less than , or equal to, 5, the loop will continue to run.
i will increase by 1 each time the loop runs.
loopnehExplanation:
i equal to 0.
The loop will run
i will increase by 1 each time the loop runs.
While i is less than , or equal to, 5, the loop will continue to run.
loop with breakExplanation: The loop will break when i=3.
break and continueExplanation: The loop will break the current loop and continue with the next value when i=3.
jumlah digit hurufmanipulasi string
lower/upper case
coba case lain
replace
deteksi browser
Catatan
Create a Date Object
The Date object is used to work with dates and times.
Date objects are created with the Date() constructor.
There are four ways of instantiating a date:
new Date() // current date and time
new Date(milliseconds) //milliseconds since 1970/01/01
new Date(dateString)
new Date(year, month, day, hours, minutes, seconds, milliseconds)
Most parameters above are optional. Not specifying, causes 0 to be passed in.
Once a Date object is created, a number of methods allow you to operate on it. Most methods allow you to get and set the year, month, day, hour, minute, second, and milliseconds of the object, using either local time or UTC (universal, or GMT) time.
All dates are calculated in milliseconds from 01 January, 1970 00:00:00 Universal Time (UTC) with a day containing 86,400,000 milliseconds.
Some examples of instantiating a date:
today = new Date()
d1 = new Date("October 13, 1975 11:13:00")
d2 = new Date(79,5,24)
d3 = new Date(79,5,24,11,33,0)
Set Dates
We can easily manipulate the date by using the methods available for the Date object.
In the example below we set a Date object to a specific date (14th January 2010):
var myDate=new Date();
myDate.setFullYear(2010,0,14);
And in the following example we set a Date object to be 5 days into the future:
var myDate=new Date();
myDate.setDate(myDate.getDate()+5);
Note: If adding five days to a date shifts the month or year, the changes are handled automatically by the Date object itself!
Compare Two Dates
The Date object is also used to compare two dates.
The following example compares today's date with the 14th January 2010:
var myDate=new Date();
myDate.setFullYear(2010,0,14);
var today = new Date();
if (myDate>today)
{
alert("Today is before 14th January 2010");
}
else
{
alert("Today is after 14th January 2010");
}
ganti gambar
Penjelasan gambar
timing alert
menghitung terus
Click on the button above. The input field will count forever, starting at 0.
hitung dan stop
(dalam contoh ini yang respond atas)
Click on the "Start count!" button above to start the timer. The input field will count forever, starting at 0. Click on the "Stop count!" button to stop the counting. Click on the "Start count!" button to start the timer again.
telling time passed
Click on the button above. The input field will tell you when two, four, and six seconds have passed.
Tidak ada komentar:
Posting Komentar