C# Класс fCraft.DateTimeUtil

Provides utility functions for working with DateTime and TimeSpan.
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
MaxTimeSpan System.TimeSpan
UnixEpoch System.DateTime

Открытые методы

Метод Описание
ParseMiniTimeSpan ( [ text ) : System.TimeSpan

Parses the given string as a TimeSpan in compact representation. Throws exceptions on failure.

ParseMiniTimespan ( [ text ) : System.TimeSpan

Parses the given string as a TimeSpan in compact representation. Throws exceptions on failure.

ToDateTime ( long timestamp ) : System.DateTime

Creates a DateTime from a UTC Unix Timestamp.

ToDateTime ( this timestamp ) : System.DateTime

Creates a DateTime from a Utc Unix Timestamp.

ToDateTime ( this str, System.DateTime &result ) : bool

Tries to create a DateTime from a string containing a Utc Unix Timestamp. If the string was empty, returns false and does not affect result.

ToDateTimeLegacy ( this str, System.DateTime &result ) : bool
ToSeconds ( this time ) : long
ToSecondsString ( this time, [ sb ) : void

Serializes the given TimeSpan to the given StringBuilder, as the number of seconds.

ToTickString ( this time, StringBuilder sb ) : StringBuilder
ToTimeSpan ( [ str, System.TimeSpan &result ) : bool

Tries to create a TimeSpan from a string containing the number of seconds. If the string was empty, returns false and sets result to TimeSpan.Zero

ToTimeSpanLegacy ( this str, System.TimeSpan &result ) : bool
ToUnixTime ( this date ) : long

Converts a DateTime to UTC Unix Timestamp.

ToUnixTimeString ( this date, StringBuilder sb ) : StringBuilder

Appends a Utc Unix Timestamp to the given StringBuilder. If the date equals DateTime.MinValue, nothing is appended.

TryParseDateTime ( long timestamp ) : System.DateTime

Creates a DateTime from a UTC Unix Timestamp.

TryParseDateTime ( [ str, System.DateTime &result ) : bool

Tries to create a DateTime from a string containing a Utc Unix Timestamp. If the string was empty, returns false and does not affect result.

TryParseMiniTimeSpan ( [ text, System.TimeSpan &result ) : bool

Attempts to parse the given string as a TimeSpan in compact representation. No exception is thrown if parsing failed.

TryParseMiniTimespan ( [ text, System.TimeSpan &result ) : bool

Attempts to parse the given string as a TimeSpan in compact representation. No exception is thrown if parsing failed.

TryParseMiniTimespan ( this text, System.TimeSpan &result ) : bool
TryParseTimeSpan ( [ str, System.TimeSpan &result ) : bool

Tries to create a TimeSpan from a string containing the number of seconds. If the string was empty, returns false and sets result to TimeSpan.Zero

Приватные методы

Метод Описание
DateTimeUtil ( ) : System
ToCompactString ( this date ) : string
ToDateTimeLegacy ( long timestamp ) : System.DateTime
ToDateTimeLegacy ( [ str, System.DateTime &result ) : bool
ToMiniString ( this span ) : string
ToSecondsString ( this time ) : string
ToTickString ( this time, [ sb ) : StringBuilder
ToTickString ( this time ) : string
ToTimeSpanLegacy ( [ str, System.TimeSpan &result ) : bool
ToUnixTimeLegacy ( this date ) : long
ToUnixTimeString ( this date, [ sb ) : StringBuilder
ToUnixTimeString ( this date ) : string
TryParseLocalDate ( [ dateString, System.DateTime &date ) : bool

Описание методов

ParseMiniTimeSpan() публичный статический Метод

Parses the given string as a TimeSpan in compact representation. Throws exceptions on failure.
text is null. The resulting TimeSpan is greater than TimeSpan.MaxValue. input has an invalid format.
public static ParseMiniTimeSpan ( [ text ) : System.TimeSpan
text [ String to parse.
Результат System.TimeSpan

ParseMiniTimespan() публичный статический Метод

Parses the given string as a TimeSpan in compact representation. Throws exceptions on failure.
text is null. The resulting TimeSpan is greater than TimeSpan.MaxValue. input has an invalid format.
public static ParseMiniTimespan ( [ text ) : System.TimeSpan
text [ String to parse.
Результат System.TimeSpan

ToDateTime() публичный статический Метод

Creates a DateTime from a UTC Unix Timestamp.
public static ToDateTime ( long timestamp ) : System.DateTime
timestamp long
Результат System.DateTime

ToDateTime() публичный статический Метод

Creates a DateTime from a Utc Unix Timestamp.
public static ToDateTime ( this timestamp ) : System.DateTime
timestamp this
Результат System.DateTime

ToDateTime() публичный статический Метод

Tries to create a DateTime from a string containing a Utc Unix Timestamp. If the string was empty, returns false and does not affect result.
public static ToDateTime ( this str, System.DateTime &result ) : bool
str this
result System.DateTime
Результат bool

ToDateTimeLegacy() публичный статический Метод

public static ToDateTimeLegacy ( this str, System.DateTime &result ) : bool
str this
result System.DateTime
Результат bool

ToSeconds() публичный статический Метод

public static ToSeconds ( this time ) : long
time this
Результат long

ToSecondsString() публичный статический Метод

Serializes the given TimeSpan to the given StringBuilder, as the number of seconds.
sb is null.
public static ToSecondsString ( this time, [ sb ) : void
time this TimeSpan to serialize.
sb [ StringBuilder to which time will be saved.
Результат void

ToTickString() публичный статический Метод

public static ToTickString ( this time, StringBuilder sb ) : StringBuilder
time this
sb StringBuilder
Результат StringBuilder

ToTimeSpan() публичный статический Метод

Tries to create a TimeSpan from a string containing the number of seconds. If the string was empty, returns false and sets result to TimeSpan.Zero
public static ToTimeSpan ( [ str, System.TimeSpan &result ) : bool
str [
result System.TimeSpan
Результат bool

ToTimeSpanLegacy() публичный статический Метод

public static ToTimeSpanLegacy ( this str, System.TimeSpan &result ) : bool
str this
result System.TimeSpan
Результат bool

ToUnixTime() публичный статический Метод

Converts a DateTime to UTC Unix Timestamp.
public static ToUnixTime ( this date ) : long
date this
Результат long

ToUnixTimeString() публичный статический Метод

Appends a Utc Unix Timestamp to the given StringBuilder. If the date equals DateTime.MinValue, nothing is appended.
public static ToUnixTimeString ( this date, StringBuilder sb ) : StringBuilder
date this
sb StringBuilder
Результат StringBuilder

TryParseDateTime() публичный статический Метод

Creates a DateTime from a UTC Unix Timestamp.
public static TryParseDateTime ( long timestamp ) : System.DateTime
timestamp long
Результат System.DateTime

TryParseDateTime() публичный статический Метод

Tries to create a DateTime from a string containing a Utc Unix Timestamp. If the string was empty, returns false and does not affect result.
public static TryParseDateTime ( [ str, System.DateTime &result ) : bool
str [
result System.DateTime
Результат bool

TryParseMiniTimeSpan() публичный статический Метод

Attempts to parse the given string as a TimeSpan in compact representation. No exception is thrown if parsing failed.
text is null.
public static TryParseMiniTimeSpan ( [ text, System.TimeSpan &result ) : bool
text [ String to parse.
result System.TimeSpan Parsed TimeSpan. Set to TimeSpan.Zero if parsing failed.
Результат bool

TryParseMiniTimespan() публичный статический Метод

Attempts to parse the given string as a TimeSpan in compact representation. No exception is thrown if parsing failed.
text is null.
public static TryParseMiniTimespan ( [ text, System.TimeSpan &result ) : bool
text [ String to parse.
result System.TimeSpan Parsed TimeSpan. Set to TimeSpan.Zero if parsing failed.
Результат bool

TryParseMiniTimespan() публичный статический Метод

public static TryParseMiniTimespan ( this text, System.TimeSpan &result ) : bool
text this
result System.TimeSpan
Результат bool

TryParseTimeSpan() публичный статический Метод

Tries to create a TimeSpan from a string containing the number of seconds. If the string was empty, returns false and sets result to TimeSpan.Zero
str is null
public static TryParseTimeSpan ( [ str, System.TimeSpan &result ) : bool
str [
result System.TimeSpan
Результат bool

Описание свойств

MaxTimeSpan публичное статическое свойство

Longest reasonable value that fCraft will allow to be entered for time spans (9999 days).
public static TimeSpan,System MaxTimeSpan
Результат System.TimeSpan

UnixEpoch публичное статическое свойство

UTC Unix epoch (1970-01-01, 00:00:00).
public static DateTime,System UnixEpoch
Результат System.DateTime