TimeSpan
v4.0
The TimeSpan class contains float values for in-game seconds, minutes, hours, days, weeks, months, seasons, and years. This is used in a variety of the GameTime methods, and can also be saved to isolate specific chunks of time that are important to your project.
Many methods which utilize this concept will allow both a TimeSpan object, or a list of floats designating the specific TimeSpan to utilize.
public float Seconds
public float Minutes
public float Hours
public float Days
public float Months
public float YearsTimeSpan does not include Weeks or Seasons, but Gametime methods will include those when handling TimeSpan objects and doing date and time calculations.
Create a TimeSpan
// Create a new Timespan object for 2 weeks -- Each value is optional, defaults to 0
TimeSpan myTimeSpan = new TimeSpan
{
Weeks = 2
};
// Create an empty Timespan, then populate it
TimeSpan respawnTime = new TimeSpan();
respawnTime.Years = 1;
respawnTime.Months = 6;Methods
Add another TimeSpan
Multiply by a multiplier float value
float valueTimespan Methods on Gametime.cs
Gametime.csThese general methods will return a TimeSpan object, which may be saved and used later.
Convert from TimeSpan
See all the conversion methods on the Gametime Properties & Methods page
Last updated
Was this helpful?