/
TimeHelper.cs
36 lines (30 loc) · 979 Bytes
/
TimeHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace GmodNetBuildBrowser
{
public static class TimeHelper
{
public static string GetUploadTimeString(DateTimeOffset uploadTimeOffset)
{
DateTime uploadTime = uploadTimeOffset.ToLocalTime().DateTime;
DateTime currentTime = DateTime.Now;
TimeSpan timeDelta = currentTime - uploadTime;
string result = uploadTime.ToString("yyyy-MM-dd HH:mm:ss");
if (timeDelta.TotalMinutes < 2)
{
result += " (just now)";
}
else if (timeDelta.TotalHours < 2)
{
result += $" ({(int)timeDelta.TotalMinutes} minutes ago)";
}
else if (timeDelta.TotalDays < 2)
{
result += $" ({(int)timeDelta.TotalHours} hours ago)";
}
return result;
}
}
}