To Relative Time Micro - CSharp System

CSharp examples for System:DateTime Format

Description

To Relative Time Micro

Demo Code


using System;//from   w w w  .j  a  va  2 s .c o  m

public class Main{
        public static string ToRelativeTimeMicro(this DateTime dt)
        {
            var ts = new TimeSpan(DateTime.UtcNow.Ticks - dt.Ticks);

            if (ts.Days <= 330)
            {
                return dt.ToString("MMM %d").ToLower();
            }
            else
            {
                return dt.ToString("MMM %d yy").ToLower();
            }
        }
}

Related Tutorials