Search Unity

Add an hour to system time and save that value?

Discussion in 'UGUI & TextMesh Pro' started by janlucvd, Aug 30, 2017.

  1. janlucvd

    janlucvd

    Joined:
    Jun 8, 2013
    Posts:
    21
    My game saves the system time when the game starts, calculates an end time 1 hour later than the start time, then checks to make sure the current time isn't greater than the end time (if it is - the game ends).

    I need help programming how to add an hour to the start time and checking the current time isn't greater than the end time.

    I get the system time with:
    currentTime = System.DateTime.Now;

    How do I add an hour to this and store the value?
    THX a mil!
     
  2. zyzyx

    zyzyx

    Joined:
    Jul 9, 2012
    Posts:
    227
    Code (CSharp):
    1. DateTime.Now.AddHours(1)
     
  3. janlucvd

    janlucvd

    Joined:
    Jun 8, 2013
    Posts:
    21
    Thanks! Part II - How do I get just the minute value from TimeSpan ts below?


    // get time app was closed and determine elapsed time

    long closeTime = long.Parse(PlayerPrefs.GetString("olddate"));
    DateTime oldDate = DateTime.FromBinary(closeTime);

    TimeSpan ts = currTime - oldDate;
     
  4. zyzyx

    zyzyx

    Joined:
    Jul 9, 2012
    Posts:
    227
    Code (CSharp):
    1. ts.Minutes;