Skip to content

Common DateTime

Ivan Kozhin edited this page Sep 7, 2020 · 4 revisions

1. Truncate

DateTime Truncate(DateTime target, DateTimePeriod period, CultureInfo cultureInfo = null)

Truncates date by the specified period. Return begin of the period.

2. CompareTo

int CompareTo(DateTime target, DateTime value, DateTimePeriod period)

Compares the value of the instance to a specified DateTime object with truncation, and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified DateTime value.

3. GetRange

IEnumerable<DateTime> GetRange(DateTime fromDate, DateTime toDate)

Returns dates range. Uses lazy implementation.

4. CombineDateAndTime

DateTime CombineDateAndTime(DateTime date, DateTime time)

Combines date part from date and time from another. Kind is getting from the time part.

5. GetStartOfPeriod

DateTime GetStartOfPeriod(DateTime target, DateTimePeriod period, CultureInfo cultureInfo = null)

Returns start of the period.

6. GetEndOfPeriod

DateTime GetEndOfPeriod(DateTime target, DateTimePeriod period, CultureInfo cultureInfo = null)

Returns end DateTime of the period.

7. FromUnixTimestamp

DateTime FromUnixTimestamp(double unixTimeStamp)

Converts from UNIX timestamp to DateTime.

8. ToUnixTimestamp

double ToUnixTimestamp(DateTime target)

Converts DateTime to UNIX timestamp.

9. GetDiff

double GetDiff(DateTime target1, DateTime target2, DateTimePeriod period)

Returns period difference between two dates. Negative values are converted to positive.

10. SetPart

DateTime SetPart(DateTime target, DateTimePeriod period, int value)

Shortcut to set date part.

Clone this wiki locally