-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
Source/Cogworks.Essentials/Extensions/DateTimeExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace Cogworks.Essentials.Extensions | ||
{ | ||
public static class DateTimeExtension | ||
{ | ||
public static int GetUnixTimeStamp(this DateTime date) | ||
=> (int)date.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; | ||
|
||
public static string ToShortDate(this DateTime date) | ||
=> date.ToString("dd MMM yyyy"); | ||
|
||
public static string GetLongMonthName(this DateTime date, CultureInfo culture = null, | ||
string defaultCultureCode = null) | ||
{ | ||
if (!defaultCultureCode.HasValue()) | ||
{ | ||
defaultCultureCode = CultureInfo.CurrentCulture.TextInfo.CultureName; | ||
} | ||
|
||
if (!culture.HasValue()) | ||
{ | ||
culture = CultureInfo.GetCultureInfo(defaultCultureCode); | ||
} | ||
|
||
return date.ToString("MMMM", culture); | ||
} | ||
|
||
public static DateTime ToDateTime(this long ticks) | ||
=> new DateTime(ticks); | ||
|
||
public static bool HasValue(this DateTime date) | ||
=> date != default; | ||
} | ||
} |