Loading...
Beranda » » » Menampilkan Tanggal dan Waktu dengan Javascript Konten Lain di Sini

Menampilkan Tanggal dan Waktu dengan Javascript

Untuk Menampilkan Hari dan Tanggal, kopas script dibawah ini kedalam eleman laman html/javascript berikut ini (letakkan sesuai dengan keinginan)

Menampilkan Tanggal Versi Bahasa INDONESIA

<script type='text/javascript'>
function dispDate(dateVal) {
    DaystoAdd=dateVal
    TodaysDate = new Date();
    TodaysDay = new Array('Minggu', 'Senin', 'Selasa','Rabu', 'Kamis', 'Jum&#39;at', 'Sabtu');
     TodaysMonth = new Array('Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember');
     DaysinMonth = new Array('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');
function LeapYearTest (Year) {
     if (((Year % 400)==0) || (((Year % 100)!=0) && (Year % 4)==0)) {
        return true;
    } else {
        return false;
    }
}
CurrentYear = TodaysDate.getYear();
if (CurrentYear < 2000) CurrentYear = CurrentYear + 1900; currentMonth = TodaysDate.getMonth(); DayOffset = TodaysDate.getDay(); currentDay = TodaysDate.getDate(); month = TodaysMonth[currentMonth]; if (month == 'February') { if (((CurrentYear % 4)==0) && ((CurrentYear % 100)!=0) || ((CurrentYear % 400)==0)) { DaysinMonth[1] = 29; } else { DaysinMonth[1] = 28; } } days = DaysinMonth[currentMonth]; currentDay += DaystoAdd; if (currentDay > days) {
if (currentMonth == 11) {
    currentMonth = 0;
    month = TodaysMonth[currentMonth];
    CurrentYear = CurrentYear + 1
} else {
    month = TodaysMonth[currentMonth+1];
}
    currentDay = currentDay - days;
}
    DayOffset += DaystoAdd;
function offsettheDate (offsetCurrentDay) {
    if (offsetCurrentDay > 6) {
         offsetCurrentDay -= 6;
         DayOffset = TodaysDay[offsetCurrentDay-1];
         offsettheDate(offsetCurrentDay-1);
    } else {
         DayOffset = TodaysDay[offsetCurrentDay];
         return true;
    }
}
offsettheDate(DayOffset);TheDate = DayOffset + ', ';
TheDate += currentDay + ' ';
TheDate += month + ' ';
if (CurrentYear<100) CurrentYear="19" + CurrentYear; TheDate += CurrentYear; document.write(' '+TheDate);
}
</script>
<script type='text/javascript'>
dispDate(0);
</script> 
 

Menampilkan Tanggal Versi Bahasa INGGRIS

<script type='text/javascript'>
function dispDate(dateVal) {
DaystoAdd=dateVal
TodaysDate = new Date();
TodaysDay = new Array('Sunday', 'Monday', 'Tuesday','Wednesday', 'Thursday', 'Friday', 'Saturday');
TodaysMonth = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
DaysinMonth = new Array('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');
function LeapYearTest (Year) {
if (((Year % 400)==0) || (((Year % 100)!=0) && (Year % 4)==0)) {
return true;
}
else {
return false;
}
}
CurrentYear = TodaysDate.getYear();
if (CurrentYear < 2000) CurrentYear = CurrentYear + 1900; currentMonth = TodaysDate.getMonth(); DayOffset = TodaysDate.getDay(); currentDay = TodaysDate.getDate(); month = TodaysMonth[currentMonth]; if (month == 'February') { if (((CurrentYear % 4)==0) && ((CurrentYear % 100)!=0) || ((CurrentYear % 400)==0)) { DaysinMonth[1] = 29; } else { DaysinMonth[1] = 28; } } days = DaysinMonth[currentMonth]; currentDay += DaystoAdd; if (currentDay > days) {
if (currentMonth == 11) {
currentMonth = 0;
month = TodaysMonth[currentMonth];
CurrentYear = CurrentYear + 1
}
else {
month =
TodaysMonth[currentMonth+1];
}
currentDay = currentDay - days;
}
DayOffset += DaystoAdd;
function offsettheDate (offsetCurrentDay) {
if (offsetCurrentDay > 6) {
offsetCurrentDay -= 6;
DayOffset = TodaysDay[offsetCurrentDay-1];
offsettheDate(offsetCurrentDay-1);
}
else {
DayOffset = TodaysDay[offsetCurrentDay];
return true;
}
}
offsettheDate(DayOffset);TheDate  = DayOffset + ', ';
TheDate += month + ' ';
TheDate += currentDay + ', ';
if (CurrentYear<100) CurrentYear="19" + CurrentYear; TheDate += CurrentYear; document.write(' '+TheDate); }
</script>  
<script type='text/javascript'>
dispDate(0);
</script> 
Sumber: Instant Web Site Tool


Menampilkan Waktu VERSI 24jam

<script type="text/javascript">
<!--
var d         = new Date();
var curr_hour = d.getHours();
var curr_min  = d.getMinutes();
document.write(curr_hour + " : " + curr_min);
//-->
</script>

Versi AM & PM

<script type="text/javascript">
<!--
var a_p       = "";
var d         = new Date();
var curr_hour = d.getHours();
if (curr_hour < 12) {
   a_p = "AM";
} else {
   a_p = "PM";
}
if (curr_hour == 0) {
   curr_hour = 12;
}
if (curr_hour > 12) {
   curr_hour = curr_hour - 12;
}

var curr_min = d.getMinutes();
curr_min = curr_min + "";
if (curr_min.length == 1) {
   curr_min = "0" + curr_min;
}

document.write(curr_hour + " : " + curr_min + " " + a_p);
//-->
</script>

CATATAN :
Kode-kode ini bukan merupakan jam aktif melainkan jam pasif yang hanya bisa menampilkan waktu saat halaman terakses. Sementara saat waktu saat ini telah berubah, jam ini tidak akan ikut mengubah waktunya:

Penulis: Unknown Lokasi: Condongcatur, Yogyakarta

Artikel Menampilkan Tanggal dan Waktu dengan Javascript, diterbitkan oleh Unknown pada hari . Semoga artikel ini dapat menambah wawasan Anda. Unknown adalah seorang yang sedang belajar Blogging, melalui eksperimen dan uji coba dari berbagai sumber. Adanya kritik dan saran sangat diharapkan..oya, jangan lupa klik like FB dan Berkomentarlah!

Tidak ada komentar:

Posting Komentar