- Home /
How should I convert timestamp in unity, which is a double, in a webserver-like BIGINT number ?
Sorry for the newbee question>
I see timestamp property (in MessageInfo or LocationInfo unity structures) is of type: Double.
But I always used BIG INT time stamp such as 1315990560
What should I do to convert that Double floating point number into a proper int timestamp ?
Answer by hojjat-reyhane · Jul 16, 2019 at 12:31 PM
For future searchers! This is how you get time as timestamp in Unity:
long time = new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds();
It will give you something like this: 1563280100.
Tested in Unity 2019
Answer by DaveA · Sep 14, 2011 at 07:44 PM
This page may help: http://msdn.microsoft.com/en-us/library/system.datetime.aspx Also http://answers.unity3d.com/questions/44415/how-to-get-real-time.html
Answer by Litobyte_Softworks · Sep 15, 2011 at 12:41 AM
I try to be more specific.
Talking about a mobile App, that need to retrieve the geographical position from GPS.
Asking the timestamp to GPS locationInfo with Unity built-in new commands (Unity Android Pro version 3.4) I get this kind of numbers:
-9.62146447728842E-24
But I think there is no convertion algorithm around to convert this DOUBLE into a BIG INT usual UNIX TIMESTAMP.
What Am I missing ?
Answer by eskimojoe · Oct 17, 2013 at 08:44 PM
Please try this:
private double ConvertToTimestamp(DateTime value)
{
//create Timespan by subtracting the value provided from
//the Unix Epoch
TimeSpan span = (value - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime());
//return the total seconds (which is a UNIX timestamp)
return (double)span.TotalSeconds;
}
Answer by Pundek · Jul 21, 2016 at 06:00 PM
I did that and is working;
private double ConvertToToTimestamp(System.DateTime value)
{
double timeStamp = (System.DateTime.UtcNow - value).TotalSeconds;
return timeStamp;
}
Your answer
Follow this Question
Related Questions
Is iPhoneInput.lastLocation.timestamp broken on Android ? 2 Answers
Why don't you allow doubles and or long for Vector3 and Quaternion....? 1 Answer
Problem With Enemy AI 0 Answers
My monster only choose one Target 2 Answers
Make Deaths end game 1 Answer