javascript - How can I set a timer to end at 12pm PST every day? -
i want create countdown on page ends @ every day. there shipping deadline purchases , want show how time remaining. there needs if statement see if it's past time , not show counter , instead show 'order ship tomorrow' div.
i've found this great javascript countdown keith wood.
and playing this code post
but since it's shipping deadline needs exact, , i'm afraid code deals browser's local time. need set 12pm pacific time.
you time server , parse in javascript. if you're using php this:
var servertime = date.parse('<?= date("r"); ?>');
this let php echo rfc2822 formatted date , javascript parse , return date object. here can continue other solutions have.
i haven't tested key time server , parse in javascript (if server isn't in correct time zone can adjust time).
update: handling timezones.
to take timezones account use datetime object in php this:
$datetime = new datetime(); $datetime->settimezone('pacific/nauru');
and echo javascript this:
var servertime = date.parse('<?= $datetime->format("r"); ?>');
again, haven't tested do.
Comments
Post a Comment