-
• #52
This what i was doing.
$now = new DateTime("now");
echo $now->format("M j, Y H:i:s O")."\n";But it doesn't work. It runs local.
Salman : if I do it, it will start at 11 here in france.
No, it will start at 11am UTC = 12 in France (UTC+1)
I tried to change the time on my computer, and it runs as it should do. But, and I don't understand why, it will run with the server time but it changes if you are in UK, FR, ou USA.. Which is dumb..
What you wrote gets "now" in the server's time but it doesn't output the timezone (+1) so the javascript interprets the time in the user's timezone.
-
• #53
What Emyr said. You're thinking too hard about this!
new Date(2013, 0, 9, 12, 00).getTime() === Date.UTC(2013, 0, 9, 11, 00) // true in France, false in the UK. Just what you need.
-
• #54
And you don't really need to get server time, Date.now() just as good as serverTime()! They both return the number of seconds since Jan 1, 1970.
But, that would still be comparing to client time right (even with compensating to UTC).
So if I change my computer clock a few days in the future, I could then register now...
Which is why it should get the time from the server, as that's the same for everyone.
Maybe that's just the paranoid developer in me ;)
-
• #55
Yes, you're right John. You can cheat by changing the clock on your computer. But you can also cheat by changing the JS/HTML and enabling the form, which isn't much harder.
I'm assuming this countdown isn't a security feature. The server should just not accept posts before the right time.
-
• #57
Don't trust the client.
-
• #58
Y2K all over again.
-
• #59
Haha, thank you guys.
The countdown is just a "decoration".
Here is my php script which enable the form :
$now = new DateTime();
$then = new DateTime("2013-01-09 12:00:00");if($now <= $then) {
// countdown
} else {
// form
}If the php refers to the server time (which is right, isn't it ?) It should show the form at noon GMT+1 (server time) right ? If yes, it's gonna be ok.
Because the countdown is in jquery but I'm using this :
function serverTime() {
var time = null; $.ajax({url: 'http://www.rouenbikepolo.com/countdown/assets/countdown/time.php', async: false, dataType: 'text', success: function(text) { time = new Date(text); }, error: function(http, message, exc) { time = new Date('error'); }}); return time;
}
To use the server time (which doesn't work but I'm wondering if the jquery is working by itself or not)
-
• #60
If you included the timezone part in the text, new Date(text) would create a correct time on the browser, regardless of the timezone of the browser. Use ISO time format
-
• #61
I'll try this.
-
• #62
I just did the change I suggested in the last page and tested it. It works even after changing the timezone on my computer.
-
• #63
Salman : It doesn't depends on computer time since the beginning. It's using something else, your internet connection or something I don't know.
The thing is, if you change from your computer it doesn't move. But from you (uk) to me (fr) its not the same and I don't know why. I've forced the timezone with php but nothing changes.
-
• #64
This is boring. I'll delete the countdown and upload the page myself at noon here.
-
• #65
;)
-
• #66
Unless you can see the good countdown on this page :)
http://www.rouenbikepolo.com/?page=registration2
shoudl be approx
20 hours 29 minutes -
• #67
Nah, 1 day 5 hours ;)
-
• #68
20h 23m right now so it's correct?
-
• #69
It's correct ! If everybody have this I'll run naked outisde (you know I can do it).
-
• #70
I wonder if people will be all like: "Remember the 2013 Rouen trip? Best java discussions of my life."
-
• #71
haha !
-
• #72
:-)
-
• #73
Right, back to business. I want to go to this. Anyone want to play with me?
-
• #74
I wonder if people will be all like: "Remember the 2013 Rouen trip? Best java discussions of my life."
Brilliant.
-
• #75
I wonder if people will be all like: "Remember the 2013 Rouen trip? Best javascript discussions of my life."
ftfy
The thing is, it doesn't run with user's time (which was the problem last year). But it run with the local time.
I tried to change the time on my computer, and it runs as it should do. But, and I don't understand why, it will run with the server time but it changes if you are in UK, FR, ou USA.. Which is dumb..