Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by DarkMagicCK · Dec 11, 2013 at 06:07 AM · c#iosbug

TimeSpan error on ios platform

Hello, I'm struggling in TimeSpan class's error on ios platform(System.TimeSpan). Whenever I use TimeSpan.FromSeconds, it throws out outside range exception [MinValue, MaxValue], so I tried to show the two values.

Just use

 Debug.Log(TimeSpan.MinValue.TotalSeconds.ToString() + "," + TimeSpan.MaxValue.TotalSeconds.ToString());

In editor, it prints the right value which is "-922337203685.478,922337203685.478". But on ios, the same code prints "4.0917397079469E+142,4.0917397079469E+142", that's really not right, and I guess it is this bug which caused the exception.

I know I can write a timespan class by myself but I'm wondering if I did something wrong because I cannot see anyone else find the same bug, or it is really a bug.

Comment
Add comment · Show 1
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 DarkMagicCK · Dec 11, 2013 at 08:12 AM 0
Share

update: I just checked DateTime.Ticks

var time = DateTime.Now; Debug.Log(time.Ticks.ToString());

In editor, this prints a reasonable value in range. And on ios, this prints a value which is out of DateTime's max Ticks value, really sucks. I guess it is is because ios has a different TicksPer$$anonymous$$illsecond at bottom, but the mono used a constant range limit which does not suit ios's tick system.

Then I can't use any thing related to DateTime's calculation. Some one can help?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by DarkMagicCK · Dec 11, 2013 at 09:27 AM

OK, bug confirmed in Unity 4.3.1f1. Because I have a slow mac and a fast pc, I always build XCode project on PC and transfer it to Mac to build on ios. This bug will occur if you build xCode project using Windows Unity Editor, maybe as I said the ticks base is different on Windows and iOS. I've reported this bug to Unity team.

Comment
Add comment · Show 3 · 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 robhuhn · Dec 11, 2013 at 09:37 AM 0
Share

Just wanted to write that I had no issues with unity 4.1 using TimeSpan on iOS e.g.

 TimeSpan timeSpan = TimeSpan.FromSeconds(time);
 string timeText = string.Format("{0:D2}:{1:D2}:{2:D2}", timeSpan.Hours, timeSpan.$$anonymous$$inutes, timeSpan.Seconds);

That project was built on a mac.

avatar image DarkMagicCK · Dec 11, 2013 at 10:15 AM 0
Share

Thanks, I've noticed that. Build on mac is O$$anonymous$$. Bug only occurs when you use Windows Unity to build XCode Project.

avatar image TimB · Mar 18, 2014 at 02:54 AM 0
Share

Thanks for posting this Dark$$anonymous$$agicC$$anonymous$$, I spent the past day trying to figure this out. I am experiencing the same issue on 4.3.1f1.

avatar image
0

Answer by dupreezarmand · Apr 03, 2014 at 08:26 PM

I went for an interesting approach :-)

Create a class and have a function to get the Unix Time natively and include that in your IOS project. Call the function from your C# script.

Function in Objective C:

extern "C" {

 double dateToUnixTimestamp() {
     return [[NSDate date] timeIntervalSince1970];
 }


}

C# Implementation:

#if UNITY_IOS [DllImport("__Internal")] private static extern double dateToUnixTimestamp();

 public Int32 DateToUnixTimestamp() {
     return (Int32)dateToUnixTimestamp();
 }

#else

 public Int32 DateToUnixTimestamp() {
     return (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
 }

#endif

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

19 People are following this question.

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

Related Questions

Distribute terrain in zones 3 Answers

Bug with EtceteraGUIManager.cs . 1 Answer

Why can't Unity use DLLImport twice for overloaded functions? 2 Answers

Multiple Cars not working 1 Answer

grab script not working 0 Answers


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