Time
This page is about the Time class available in PeyrSharp.Core.Converters. You can find here all of its methods.
INFO
This class is static.
Compatibility
The Time class is part of the PeyrSharp.Core module, which is compatible with all of these frameworks and platforms:
| Package/Platform | Windows | macOS | Linux + others |
|---|---|---|---|
| Core | ✅ | ✅ | ✅ |
| Framework | .NET 6 | .NET 7 | .NET 8 |
| Core | ✅ | ✅ | ✅ |
Methods
ToSeconds(d, timeUnits)
Definition
Converts a specified time unit value to seconds. For instance, you can convert days, hours or minutes to seconds. It returns a double value.
INFO
This method can also be used in PeyrSharp.Extensions.
Arguments
| Type | Name | Meaning |
|---|---|---|
double | d | The time unit to convert. |
TimeUnits | timeUnits | The unit of the time. (ex: minutes, hours...) |
Usage
using PeyrSharp.Core.Converters;
using PeyrSharp.Enums;
double seconds = Time.ToSeconds(5, TimeUnits.Minutes);
// seconds = 300ToMinutes(d, timeUnits)
Definition
Converts a specified time unit value to minutes. For instance, you can convert days, hours or seconds to minutes. It returns a double value.
INFO
This method can also be used in PeyrSharp.Extensions.
Arguments
| Type | Name | Meaning |
|---|---|---|
double | d | The time unit to convert. |
TimeUnits | timeUnits | The unit of the time. (ex: minutes, hours...) |
Usage
using PeyrSharp.Core.Converters;
using PeyrSharp.Enums;
double min = Time.ToMinutes(120, TimeUnits.Seconds);
// min = 2ToHours(d, timeUnits)
Definition
Converts a specified time unit value to hours. For instance, you can convert days, minutes or seconds to hours. It returns a double value.
INFO
This method can also be used in PeyrSharp.Extensions.
Arguments
| Type | Name | Meaning |
|---|---|---|
double | d | The time unit to convert. |
TimeUnits | timeUnits | The unit of the time. (ex: minutes, hours...) |
Usage
using PeyrSharp.Core.Converters;
using PeyrSharp.Enums;
double hours = Time.ToHours(1, TimeUnits.Days);
// hours = 24ToDays(d, timeUnits)
Definition
Converts a specified time unit value to days. For instance, you can convert hours, minutes or seconds to days. It returns a double value.
INFO
This method can also be used in PeyrSharp.Extensions.
Arguments
| Type | Name | Meaning |
|---|---|---|
double | d | The time unit to convert. |
TimeUnits | timeUnits | The unit of the time. (ex: minutes, hours...) |
Usage
using PeyrSharp.Core.Converters;
using PeyrSharp.Enums;
double days = Time.ToDays(72, TimeUnits.Hours);
// days = 3UnixTimeToDateTime(unixTime)
Available in version 1.1 and higher.
Definition
Converts Unix Time to DateTime. It returns a DateTime value.
Arguments
| Type | Name | Meaning |
|---|---|---|
int | unixTime | The Unix Time to convert. |
Usage
using PeyrSharp.Core.Converters;
var date = Time.UnixTimeToDateTime(1670144268); // 12/04/2022 08:57:48DateTimeToUnixTime(dateTime)
Available in version 1.1 and higher.
Definition
Converts DateTime to Unix Time. It returns an int value.
Arguments
| Type | Name | Meaning |
|---|---|---|
DateTime | dateTime | The converted DateTime in Unix Time. |
Usage
using PeyrSharp.Core.Converters;
int unix = Time.DateTimeToUnixTime(new(2022, 12, 4, 8, 57, 48, DateTimeKind.Utc));
// unix = 1670144268