Table of Contents

Class XDateTime

Extension methods for the DateTime class.

Inheritance
System.Object
XDateTime
Namespace: Galaxon.Core.Time
Assembly: Galaxon.Core.dll
Syntax
public static class XDateTime : object

Fields

JulianPeriodOffset

The number of days from the start of the Julian period to the start of the epoch used by .NET (0001-01-01 00:00:00 UTC). GetTotalDays(DateTime)

Declaration
public const double JulianPeriodOffset = null
Field Value
Type Description
System.Double
| Improve this Doc View Source

Methods

AddWeeks(DateTime, Double)

Add a number of weeks to a DateTime to get a new DateTime.

Declaration
public static DateTime AddWeeks(this DateTime dt, double weeks)
Parameters
Type Name Description
DateTime dt

A DateTime.

System.Double weeks

The number of weeks to add.

Returns
Type Description
DateTime
| Improve this Doc View Source

FromJulianDay(Double)

Convert a Julian Day value to a DateTime object.

Declaration
public static DateTime FromJulianDay(double jd)
Parameters
Type Name Description
System.Double jd

The Julian Day value. May include a fractional part indicating the time of day.

Returns
Type Description
DateTime

A new DateTime object.

| Improve this Doc View Source

FromTotalDays(Double)

Create a new DateTime given the number of days since the start of the epoch.

Declaration
public static DateTime FromTotalDays(double days)
Parameters
Type Name Description
System.Double days

The number of days. May include a fractional part indicating the time of day.

Returns
Type Description
DateTime

A new DateTime object.

| Improve this Doc View Source

FromTotalSeconds(Double)

Create a new DateTime given the number of seconds since the start of the epoch.

Declaration
public static DateTime FromTotalSeconds(double seconds)
Parameters
Type Name Description
System.Double seconds

The number of seconds.

Returns
Type Description
DateTime

A new DateTime object.

| Improve this Doc View Source

FromTotalYears(Double)

Create a new DateTime given the number of years since the start of the epoch.

Declaration
public static DateTime FromTotalYears(double years)
Parameters
Type Name Description
System.Double years

The number of years. May include a fractional part.

Returns
Type Description
DateTime

A new DateTime object.

| Improve this Doc View Source

GetDateOnly(DateTime)

Get the date part of a DateTime as a DateOnly object. An alternative to the Date property, which returns a DateTime.

Declaration
public static DateOnly GetDateOnly(this DateTime dt)
Parameters
Type Name Description
DateTime dt

The DateTime.

Returns
Type Description
DateOnly

The date part of the DateTime.

| Improve this Doc View Source

GetTimeOnly(DateTime)

Get the time part of a DateTime as a TimeOnly object. An alternative to the TimeOfDay property, which returns a TimeSpan.

Declaration
public static TimeOnly GetTimeOnly(this DateTime dt)
Parameters
Type Name Description
DateTime dt

The DateTime.

Returns
Type Description
TimeOnly

The time part of the DateTime.

| Improve this Doc View Source

GetTotalDays(DateTime)

Get the total number of days from the start of the epoch to the datetime.

Declaration
public static double GetTotalDays(this DateTime dt)
Parameters
Type Name Description
DateTime dt

The DateTime instance.

Returns
Type Description
System.Double

The number of days since the epoch start.

| Improve this Doc View Source

GetTotalSeconds(DateTime)

Get the total number of seconds from the start of the epoch to the datetime.

Declaration
public static double GetTotalSeconds(this DateTime dt)
Parameters
Type Name Description
DateTime dt

The DateTime instance.

Returns
Type Description
System.Double

The number of seconds since the epoch start.

| Improve this Doc View Source

GetTotalYears(DateTime)

Get the number of years between the start of the epoch and the start of the date.

Declaration
public static double GetTotalYears(this DateTime dt)
Parameters
Type Name Description
DateTime dt

The DateTime instance.

Returns
Type Description
System.Double

The number of years since the epoch start.

| Improve this Doc View Source

ToIsoString(DateTime)

Format the date using ISO format YYYY-MM-DDThh:mm:ss. This format is useful for databases. The time zone is not shown. For that, call ToString() with the format specifier "U" or UniversalSortableDateTimePattern. See https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tostring?view=net-7.0

Declaration
public static string ToIsoString(this DateTime date)
Parameters
Type Name Description
DateTime date

The DateTime instance.

Returns
Type Description
System.String

A string representing the datetime in ISO format.

| Improve this Doc View Source

ToJulianDay(DateTime)

Express the DateTime as a Julian Day. The time of day information in the DateTime will be expressed as the fractional part of the return value. Note, however, a Julian Day begins at 12:00 noon.

Declaration
public static double ToJulianDay(this DateTime dt)
Parameters
Type Name Description
DateTime dt

The DateTime instance.

Returns
Type Description
System.Double

The Julian Day value

| Improve this Doc View Source
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX | Galaxy logo by Freepik