Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Unix Time Class


XerShade
 Share

Recommended Posts

A simple class I made in C# that uses Unix Time as a replacement for Environment.Tickcount.

```
/*
* Author: XerShade
* Author Website: http://www.xershade.tk/
*/

using System;

namespace UnixTime
{
/// /// Tick Count object, used to generate time related values.
/// Created as a replacement for so the game's time
/// does not reset when the computer running it resets.
///

public sealed class TickCount
{
/// /// Defines a object that is created using Unix time's values.
///

static DateTime _UnixTime = new DateTime(1970, 1, 1, 0, 0, 0);

/// /// Generates the number of ticks since Unix Time started.
///

public static Double Get
{
get
{
// Use Unix Time and DateTime.Now to calculate the value.
return (DateTime.Now - TickCount._UnixTime).TotalMilliseconds;
}
}

/// /// Generates the number of seconds since Unix Time started.
///

public static Double Get
{
get
{
// Use Unix Time and DateTime.Now to calculate the value.
return (DateTime.Now - TickCount._UnixTime).TotalSeconds;
}
}

/// /// Generates the current date as a string.
///

public static String GetDate
{
get
{
// Use DateTime.Now to calculate the value.
return DateTime.Now.ToLongDateString();
}
}

/// /// Generates the current date as a short string.
///

public static String GetShortDate
{
get
{
// Use DateTime.Now to calculate the value.
return DateTime.Now.ToShortDateString();
}
}

/// /// Generates the current time as a string.
///

public static String GetTime
{
get
{
// Use DateTime.Now to calculate the value.
return DateTime.Now.ToLongTimeString();
}
}

/// /// Generates the current time as a short string.
///

public static String GetShortTime
{
get
{
// Use DateTime.Now to calculate the value.
return DateTime.Now.ToShortTimeString();
}
}
}
}

```
Link to comment
Share on other sites

  • 2 weeks later...
Well it pretty much does the same as this: [http://php.net/manual/en/function.time.php](http://php.net/manual/en/function.time.php)

So these ticks if you /1000 to make them into seconds can work with php scripts. Adding another method in to get the seconds now.
Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...