Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question about converting System.DateTime.Now.ToString ();

Discussion in 'Scripting' started by Sylvir, Mar 4, 2016.

  1. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    Hey,

    How would I go about converting System.Date.Time.Now.ToString() to a set up numbers that i can then subtract to find the difference of the System.Date.Time.Now.ToString() of when an application was opened and when it was last closed?

    Thanks!
     
  2. SneeKeeFahk

    SneeKeeFahk

    Joined:
    Jan 25, 2015
    Posts:
    26
    Code (CSharp):
    1. // store the start dateTime
    2. DateTime startTime = DateTime.Now;
    3.  
    4. /// later in your code
    5. TimeSpan span = DateTime.Now - startTime;
    6. // span now contains an object that represents the difference in time between the 2 dateTime objects.
     
  3. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    thank you very much appreciate it