Jump to content

Small test required

homeap5

Hi everyone (after long time of inactivity, just for one more post)

 

I need small help from someone that lives in different timezone than mine (I'm from Europe, UTC+2).

 

If anyone can tell me if the time displayed here:

http://www.thrash.pl/helptime.html

is the same as your time.

 

If you're living outside Europe, you should see different time and that is what I want to achieve (to show my local time for everyone, no matter what timezone someone lives). But I can't test it myself.

 

I know how to do it in php (that's easy), but if I am not so good in js.

Link to comment
Share on other sites

Link to post
Share on other sites

It works,it shows the correct time.

A PC Enthusiast since 2011
AMD Ryzen 7 5700X@4.65GHz | GIGABYTE GTX 1660 GAMING OC @ Core 2085MHz Memory 5000MHz
Cinebench R23: 15669cb | Unigine Superposition 1080p Extreme: 3566
Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, Vishera said:

It works,it shows the correct time.

It supposed to show WRONG time. I mean - it supposed to show MY time (UTC+2).

If you're living in US for example, this should show you 10:00 right now, not your time.

 

Link to comment
Share on other sites

Link to post
Share on other sites

You use JavaScript. JavaScript runs in the people's browser. So the time will be their's.
If you want your server's time, use PHP for example.

The browser doesn't get your server's time. It gets this code:
 

<html><head><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
#dimmm{transition: all 3s linear;display:block;width:100%;background-color:#FFFFFF;opacity:0;text-align:center}
</style>
</head><body style='background-color:#FFFFFF' onLoad='javascript:showme();'>
<div id='dimmm'>
<br><center>
<div id="txt" style="border-style:none;display:inline-block;margin:10px;color:#000000;font-family:Courier New;font-size:20px;line-height:30px;font-weight:bold;width:300px;height:80px;text-align:center"></div>
&nbsp;
</div>
<script type='text/javascript'>
function showme(){
document.getElementById("dimmm").style.opacity = "1";
}

function startTime() {



offset=2;

    d = new Date();

    utc = d.getTime() + (d.getTimezoneOffset() * 60000);

    nd = new Date(utc + (3600000*offset));

aa1=nd.getHours();
aa2=nd.getMinutes();
if (aa2 < 10)  aa2 = '0'+aa2;
aa3=nd.getSeconds();
 if (aa3 < 10)  aa3 = '0'+aa3;


    document.getElementById('txt').innerHTML =
    "now it's " + aa1 + ":"+ aa2 + ":" +aa3 + " here";


    var t = setTimeout(startTime, 500);
}
function checkTime(i) {
    if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;
}
startTime();
</script>
</body></html>

So the new Date runs in the browser.

 

PHP doesn't send it's code. The code, the browser receives will not contain the PHP code. I will just contain the stuff you write by "echo".

If you want to use JavaScript really bad, you can use it to call a website, which shows the time and extract the time string from there.

My build:

CPU

Intel Core i7 9700 8x 3.00GHz So.1151

 

CPU cooler

be quiet! Shadow Rock Slim

 

Motherboard

MSI B360-A PRO Intel B360 So.1151 Dual Channel DDR4 ATX

 

RAM

16GB (4x 4096MB) HyperX FURY black DDR4-2666

 

GPU

8GB Gigabyte GeForce RTX2070 WindForce 2X 3xDP/HDMI

 

SSD

500GB Samsung 970 Evo Plus M.2 2280

 

HDD

4000GB WD Red WD40EFRX Intellipower 64MB 3.5" (8.9cm) SATA 6Gb/s

 

Power Supply

bequiet! Straight Power 750W Platinum

 

Case

Fractal Design Define R6
3x bequiet! Silent Wings 3 PWM

Link to comment
Share on other sites

Link to post
Share on other sites

49 minutes ago, suedseefrucht said:

You use JavaScript. JavaScript runs in the people's browser. So the time will be their's.
If you want your server's time, use PHP for example.

The browser doesn't get your server's time. It gets this code:
 

<html><head><meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
#dimmm{transition: all 3s linear;display:block;width:100%;background-color:#FFFFFF;opacity:0;text-align:center}
</style>
</head><body style='background-color:#FFFFFF' onLoad='javascript:showme();'>
<div id='dimmm'>
<br><center>
<div id="txt" style="border-style:none;display:inline-block;margin:10px;color:#000000;font-family:Courier New;font-size:20px;line-height:30px;font-weight:bold;width:300px;height:80px;text-align:center"></div>
&nbsp;
</div>
<script type='text/javascript'>
function showme(){
document.getElementById("dimmm").style.opacity = "1";
}

function startTime() {



offset=2;

    d = new Date();

    utc = d.getTime() + (d.getTimezoneOffset() * 60000);

    nd = new Date(utc + (3600000*offset));

aa1=nd.getHours();
aa2=nd.getMinutes();
if (aa2 < 10)  aa2 = '0'+aa2;
aa3=nd.getSeconds();
 if (aa3 < 10)  aa3 = '0'+aa3;


    document.getElementById('txt').innerHTML =
    "now it's " + aa1 + ":"+ aa2 + ":" +aa3 + " here";


    var t = setTimeout(startTime, 500);
}
function checkTime(i) {
    if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;
}
startTime();
</script>
</body></html>

So the new Date runs in the browser.

 

PHP doesn't send it's code. The code, the browser receives will not contain the PHP code. I will just contain the stuff you write by "echo".

If you want to use JavaScript really bad, you can use it to call a website, which shows the time and extract the time string from there.

 

This code (it's not mine) supposed to be timezone independent, that is getTimezoneOffset for.

 

EDIT: Finally I found my friend online who lives in different timezone and he confirm that it working (shows my time instead of his).

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×