DateTimeExtensionMethods

public static class DateTimeExtensionMethods
Provides extension methods for some date/time modifications.

Methods

HourFactor

#Example
public static double HourFactor(this DateTime time)
Gets the normalised factor into the current hour.
time (DateTime)Time to measure.
Normalised factor.

HourSpan

#Example
public static TimeSpan HourSpan(this DateTime time)
Gets the timespan into the current hour.
time (DateTime)Time to measure.
Timespan. Always between zero and one hour.

MinuteFactor

#Example
public static double MinuteFactor(this DateTime time)
Gets the normalised factor into the current minute.
time (DateTime)Time to measure.
Normalised factor.

MinuteSpan

#Example
public static TimeSpan MinuteSpan(this DateTime time)
Gets the timespan into the current minute.
time (DateTime)Time to measure.
Timespan. Always between zero and one minute.

SecondFactor

#Example
public static double SecondFactor(this DateTime time)
Gets the normalised factor into the current second.
time (DateTime)Time to measure.
Normalised factor.

SecondSpan

#Example
public static TimeSpan SecondSpan(this DateTime time)
Gets the timespan into the current second.
time (DateTime)Time to measure.
Timespan. Always between zero and one second.

ToAgeString

#Example
public static string ToAgeString(this TimeSpan age, bool years = true, bool months = true, bool weeks = true, bool days = true)
Format the age of a time span.
age (TimeSpan)
years (bool = true)
months (bool = true)
weeks (bool = true)
days (bool = true)

ToDateTime

#Example
public static DateTime ToDateTime(this double number)
Convert a floating point number into a DateTime instance counting the days since January 1st 2020. Note that overflow will be handled by returning a DateTime.MinValue or DateTime.MaxValue.
number (double)Number to convert.

ToNumber

#Example
public static double ToNumber(this DateTime date)
Convert a DateTime into a floating point number counting the days since January 1st 2020.
date (DateTime)Date to convert.
Number. Note it may be negative.

ToNumber

#Example
public static double ToNumber(this TimeSpan time)
Convert a TimeSpan into a floating point number counting the total number of days.
time (TimeSpan)Time to convert.
Number. Note it may be negative.

ToTimeSpan

#Example
public static TimeSpan ToTimeSpan(this double number)
Convert a floating point number into a TimeSpan instance using total days. Note that overflow will be handled by returning a TimeSpan.MinValue or TimeSpan.MaxValue.
number (double)Number to convert.