Skip to content

Commit

Permalink
Added UnixTimeToDateTime() method (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Dec 4, 2022
1 parent d736810 commit 584d971
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions PeyrSharp.Core/Converters/Time.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,17 @@ public static class Time
TimeUnits.Days => d,// Return the expected value
_ => d,
};

/// <summary>
/// Converts Unix Time to a <see cref="DateTime"/>.
/// </summary>
/// <param name="unixTime">The Unix Time.</param>
/// <returns>The unix time converted to <see cref="DateTime"/>.</returns>
public static DateTime UnixTimeToDateTime(int unixTime)
{
DateTime dtDateTime = new(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); // Create a date
dtDateTime = dtDateTime.AddSeconds(unixTime).ToLocalTime(); // Add the seconds
return dtDateTime; // Return the result
}
}
}

0 comments on commit 584d971

Please sign in to comment.