SoFunction
Updated on 2025-03-07

How to use Unity timestamps

Although timestamps are a relatively small feature in game development? However, if this function is missing, it will lead to development difficulties. In order to help everyone develop, let’s introduce the use of timestamps to you below. Let’s take a look.

Convert timestamps to time

publicstatic string getTime(string_time)   
  { 
    stringtimeStamp = _time;   
    DateTime dtStart = (newDateTime(1970, 1, 1));   
    longlTime = (timeStamp + "0000000");   
    TimeSpan toNow = newTimeSpan(lTime);    
    DateTime dtResult = (toNow); 
    (dtResult);
    stringdate = ().ToString(); 
    stringtime = ().ToString(); 
    string[] date_arr = ('/');  
    string[] time_arr = (':');  
    stringresult = date_arr[0]+"moon"+date_arr[1]+"day"+" "+time_arr[0]+"hour"+time_arr[1]+"point";      
    returnresult;  
  }

Calculate the time interval between the current timestamp and the target timestamp

publicstring DateStringFromNow(stringdt) 
  {
    stringtimeStamp = dt;   
    DateTime dtStart = (newDateTime(1970, 1, 1));   
    longlTime = (timeStamp + "0000000");   
    TimeSpan toNow = newTimeSpan(lTime);    
    DateTime dtResult = (toNow); 
    TimeSpan span =  - dtResult; 
    if( > 90) 
    {
      return"3 months ago";
 
    }
    else
    if( > 60) 
    {
      return"2 months ago";
 
    }
    elseif (  > 30 ) 
    {
       
      return"1 month ago";
    }
    elseif ( > 14) 
    {
      return
        "2 weeks ago";
    }
    elseif ( > 7) 
    {
      return"1 week ago";
    }
     
    elseif ( > 1) 
    {
      ("{0}Day ago",
                 (int)());
    }
    elseif ( > 1) 
    {
      ("{0}Hour ago", (int)());
    }
    elseif ( > 1) 
    {
      ("{0}Minutes ago", (int)());
    }
    elseif ( >= 1) 
    {
      ("{0}Seconds ago",
                 (int)());
    }
     
    else{ 
      return"1 second ago";
       
    }
}

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.