using System;
using System.Collections.Generic;
using System.Text;
public static class TimeSpanExtensions
{
public static string FromNowFormatted(this DateTime date)
{
var sb = new StringBuilder();
var t = DateTime.Now - date;
var dic = new Dictionary<string, int>
{
{"years", (int)(t.Days / 365)},
{"months", (int)(t.Days / 12)},
{"days", t.Days},
{"hours", t.Hours},
{"minutes", t.Minutes},
{"seconds", t.Seconds},
};
bool b = false;
foreach (var e in dic)
{
if (e.Value > 0 || b)
{
var v = e.Value;
var k = v == 1 ? e.Key.TrimEnd('s') : e.Key ;
sb.Append(v + " " + k + "\n");
b = true;
}
}
return sb.ToString();
}
}
public class Test
{
public static void Main()
{
var d1 = new DateTime(2013,1,1,0,0,1);
Console.WriteLine(d1.FromNowFormatted());
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLlRleHQ7CiAKcHVibGljIHN0YXRpYyBjbGFzcyBUaW1lU3BhbkV4dGVuc2lvbnMKewogICAgcHVibGljIHN0YXRpYyBzdHJpbmcgRnJvbU5vd0Zvcm1hdHRlZCh0aGlzIERhdGVUaW1lIGRhdGUpCiAgICB7CiAgICAgICAgdmFyIHNiID0gbmV3IFN0cmluZ0J1aWxkZXIoKTsKICAgICAgICAKICAgICAgICB2YXIgdCA9IERhdGVUaW1lLk5vdyAtIGRhdGU7CiAgICAgICAgCiAgICAgICAgdmFyIGRpYyA9IG5ldyBEaWN0aW9uYXJ5PHN0cmluZywgaW50PgogICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICB7InllYXJzIiwgKGludCkodC5EYXlzIC8gMzY1KX0sCiAgICAgICAgICAgICAgICAgICAgICB7Im1vbnRocyIsIChpbnQpKHQuRGF5cyAvIDEyKX0sCiAgICAgICAgICAgICAgICAgICAgICB7ImRheXMiLCB0LkRheXN9LAogICAgICAgICAgICAgICAgICAgICAgeyJob3VycyIsIHQuSG91cnN9LAogICAgICAgICAgICAgICAgICAgICAgeyJtaW51dGVzIiwgdC5NaW51dGVzfSwKICAgICAgICAgICAgICAgICAgICAgIHsic2Vjb25kcyIsIHQuU2Vjb25kc30sCiAgICAgICAgICAgICAgICAgIH07CiAgICAgICAgCiAgICAgICAgYm9vbCBiID0gZmFsc2U7CiAgICAgICAgZm9yZWFjaCAodmFyIGUgaW4gZGljKQogICAgICAgIHsgICAgICAgICAgICAgICAgCiAgICAgICAgICAgIGlmIChlLlZhbHVlID4gMCB8fCBiKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB2YXIgdiA9IGUuVmFsdWU7CiAgICAgICAgICAgICAgICB2YXIgayA9IHYgPT0gMSA/IGUuS2V5LlRyaW1FbmQoJ3MnKSA6IGUuS2V5IDsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgc2IuQXBwZW5kKHYgKyAiICIgKyBrICsgIlxuIik7CiAgICAgICAgICAgICAgICBiID0gdHJ1ZTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAKICAgICAgICByZXR1cm4gc2IuVG9TdHJpbmcoKTsKICAgIH0KfQogCnB1YmxpYyBjbGFzcyBUZXN0CnsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKICAgIHsKICAgICAgICB2YXIgZDEgPSBuZXcgRGF0ZVRpbWUoMjAxMywxLDEsMCwwLDEpOwogICAgICAgIAogICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKGQxLkZyb21Ob3dGb3JtYXR0ZWQoKSk7CiAgICB9Cn0=