Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Litobyte_Softworks · Sep 14, 2011 at 06:47 PM · doublefloatingpointtimestamp

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 ?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
3

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SpinyPirate · Jul 29, 2019 at 05:07 PM 1
Share

Your comment saved my day! Thank you, good sir :)

avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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 ?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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;
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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;
     }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges