PHP Live Clock with JQUERY

Buat File jam.php

<?php
    date_default_timezone_set('Asia/Jakarta'); // atau timezone lain
    echo $timestamp = date('H:i:s');

Tambahkan script js di bagian bawah halaman,

$(document).ready(function() {
    setInterval(timestamp, 1000);
});

function timestamp() {
    $.ajax({
        url: 'http://localhost/jam.php',
        success: function(data) {
            $('#timestamp').html(data);
        },
    });
}

Untuk menampilkan, tambahkan tag <div> seperti di bawah ini

<div id="timestamp"></div>

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google

You are commenting using your Google account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.