DateTimeExtensionMethods

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

Methods

HourFactor

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

HourSpan

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

MinuteFactor

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

MinuteSpan

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

SecondFactor

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

SecondSpan

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

ToAgeString

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

ToDateTime

#Example
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.
public static DateTime ToDateTime(
this double
number
Number to convert.
)

ToNumber

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

ToNumber

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

ToTimeSpan

#Example
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.
public static TimeSpan ToTimeSpan(
this double
number
Number to convert.
)