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. Dismiss Notice

How to convert a total os seconds to a TimeStamp?

Discussion in 'Scripting' started by RealidadEmpoderada, Jan 27, 2017.

  1. RealidadEmpoderada

    RealidadEmpoderada

    Joined:
    Sep 28, 2016
    Posts:
    13
    I have a total a seconds from a defined time in the past and I need to obtain a date of this total of seconds.
    The idea is to manage a virtual calendary counting virtual seconds.
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
  3. RealidadEmpoderada

    RealidadEmpoderada

    Joined:
    Sep 28, 2016
    Posts:
    13
    I need is convert a quanty of seconds to a date and time.
    For example if I have 1000000000 of seconds I need to have with is the date from the begining of the times...
     
  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    By default a new DateTime starts out at {01/01/0001 00:00:00}

    You can then call AddSeconds(1000000000) to get the current date time.
     
    lordofduct likes this.
  5. Reaksmey-Rt

    Reaksmey-Rt

    Joined:
    Sep 24, 2014
    Posts:
    1
    public string ConvertToTimestamp(long unixTime)
    {
    DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc).ToLocalTime() ;// hour local zone
    long unixTimeStampInTicks = (unixTime * TimeSpan.TicksPerMillisecond);
    string date = new DateTime(unixStart.Ticks + unixTimeStampInTicks, System.DateTimeKind.Utc).ToString();
    return date;
    }