Skip to content

Time.cs - C# extension methods for DateTime to calculate relative time and age

Notifications You must be signed in to change notification settings

faisalman/time-cs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Time.cs

Extended C# DateTime Library

Example

using System;
using Faisalman.Utils;

class Program
{
  static void Main(string[] args)
  {
    DateTime d1 = DateTime.Now;
    DateTime d2 = d1.AddSeconds(30);
    DateTime d3 = new DateTime(1970, 8, 21);
    DateTime d4 = new DateTime(2014, 4, 30);

    // As DateTime extension method
    Console.WriteLine(d2.GetRelativeTime(d1)); // output: "about 30 seconds ago"
    Console.WriteLine(d1.GetRelativeTime(d2)); // output: "in about 30 seconds"
    // As usual static method
    Console.WriteLine(Time.GetRelativeTime(d2, d1)); // output: "about 30 seconds ago"
    Console.WriteLine(Time.GetRelativeTime(d1, d2)); // output: "in about 30 seconds"

    Console.WriteLine(Time.GetAge(d3, d4)); // output: "43 years 8 months 9 days";

    Console.ReadLine();
  }
}

License

MIT License

Copyright © 2013 Faisalman <fyzlman@gmail.com>

About

Time.cs - C# extension methods for DateTime to calculate relative time and age

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages