- Home /
Get date from server?
Here comes a .NET question:
I need to save in a database the current date when the player registered, or something else.
But I want to record the "real" date, not the user machine's date, as he could easily change this date.
So I need to record the date from a reference outside the user's machine, maybe from a server, how could I do this?
(The function System.DateTime.Now gives me the client machine's date)
I thought I could create a PHP script that gets the current date from the server, then I could read the date from that page. Is there something wrong with this method? Are there any alternatives?
Been quite awhile since I've messed with my DB , but if I remember right when I was setting it up there was a field I could put in there specifically for the date and it would automatically set itself whenever a new entry was made in that table. e.g. new user registered, it saved their name and password and all that junk by way of code ; but auto-saved the date it happened.
You should check in yours if you can do that.
...Edit Yeah, I just checked. If you can in yours, make a column of the type 'timestamp' in your users table and set it's default value to be "CURRENT_TI$$anonymous$$ESTA$$anonymous$$P" .
Yes, thanks, but there's a new problem:
I can set only one CURRENT_TI$$anonymous$$ESTA$$anonymous$$P as default for each table.
I need to record the last login date too.But I can do it simply updating the column with the CURRENT_TI$$anonymous$$ESTA$$anonymous$$P function.
Ps.: I'm using $$anonymous$$ySQL.
maybe current_timestamp was what I used for last login... i think it might update every time that row of the table is updated, so that wouldn't be good for the registered date ; I can't remember exactly what I did for that stuff it's been so long. All I checked earlier was made a new table and added a couple columns to it and inserted something into the 2nd column to see if the timestamp field auto-filled lol ... but yeah, let the cur-ts set itself for last logins, then just include a part in your registration code PHP to set the registered date once. ---this isn't really unity specific lol but whatever
Not sure about the database, but in .NET you could get the current time from a NIST time server. I used this in a unity project not long ago. Doesn't work in the web player, though. Let me know if the function would be useful to you.
You can also use the date() function in php to get the current date and then save that value in your database.
Answer by Leaton · Nov 20, 2017 at 02:20 AM
Here is the answer I use to keep my time accurate across all devices by utilizing the internet/server time : http://leatonm.net/unity3d-internet-time-date-setup-guide-stop-time-cheat/