I retrive NTP time from google ntp. But It’s get double data. I want to convert to Date format.
give us an example of the format you are getting from google

I get d = 3702904476118.82.
I want to convert to time.
MM/dd/yyyy HH:mm:ss.fff
using System;
DateTime dateTime = new DateTime(1970, 1, 1).AddMilliseconds(d).ToLocalTime();
I think that will do it in c#.
I think I should covert first. Because I Debug.Log(DateTime.Now.ToOADate());. It’s return 42859.988032135. It’s not equal d.
the good news is that 3702904476118.82 is in milliseconds, so you just need to do a little math to convert it. or do some more googling to see if someone has a solution already.
this might be what you need
var time = TimeSpan.FromMilliseconds(milliseconds);
My code :
var time = TimeSpan.FromMilliseconds(d);
Debug.Log(time.ToString());
Result :
42857.17:03:40.3040000
How to fix this ? Thank you.
try this
var time = new DateTime(d * 10000);
Debug.Log(time.ToString("yyyy-MM-ddTHH:mm:ssZ"));
I convert to long because d is double.
var time = new DateTime((long)(d * 10000));
Debug.Log(time.ToString(“yyyy-MM-ddTHH:mm:ssZ”));
Result : 0118-05-05T17:18:23Z It’s not work. ![]()
convert it to an int. this should not fix the issue
int intd = Convert.ToInt32(d);
var time = new DateTime(intd * 10000);
//and try
//var time = new DateTime(intd);
string datetime = time.ToString("yyyy-MM-ddTHH:mm:ssZ");
Debug.Log(datetime);
It’s error. OverflowException: Value is greater than Int32.MaxValue or less than Int32.MinValue
Convert.ToInt64(d)
I think it’s better to take a step back and figure out what the NTP time actually represents.
This link implies the actual start date is Jan 1, 1900, so you probably should start counting from there.
EDIT: Hmm, this is confusing. From the linked reference from within that link:
So I’m not sure if it’s 1900 or 1990. Try both and see what you get.
double d;
d = TimeCheatingDetector.GetOnlineTime("time1.google.com");
Int64 intd = Convert.ToInt64(d);
var time = new DateTime(intd * 10000);
//and try
//var time = new DateTime(intd);
string datetime = time.ToString("MM/dd/yyyy HH:mm:ss.fff");
Debug.Log(datetime);
Result : 05/05/0118 18:00:52.651
I have no idea about time code.
As I said earlier, try this. You can then play with the date until it is correct;
var dateTime = new DateTime(1970, 1, 1).AddMilliseconds(d).ToLocalTime();
d = TimeCheatingDetector.GetOnlineTime("time1.google.com");
var dateTime = new DateTime(1970, 1, 1).AddMilliseconds(d).ToLocalTime();
Debug.Log(dateTime);
Result : 05/05/2087 01:32:28
It’s time error.
Only 70 years off. I believe @BlackPete had the right idea
Post your code for your getonlinetime function.
Thank you very much! My code getonlinetime it’s set date at 1900.
@vistriter Hey, feel free to ask at the Anti-Cheat Toolkit forum thread next time, I’d provided you an example and details about 1900 year right away =)
Just accidentally came across this thread and saw you’re asking about ACTk’s method here instead of official thread on this forum for the some reason.