Class DateTimeExtensions
Inheritance
DateTimeExtensions
Assembly: Lett.Extensions.dll
Syntax
public static class DateTimeExtensions
Methods
|
Improve this Doc
View Source
EndOfDay(DateTime)
获取 DateTime 的结束 (year-month-day 23:59:59.999)
Declaration
public static DateTime EndOfDay(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 1, 2, 3);
var rs = dt.EndOfDay(); // rs == new DateTime(2019, 4, 1, 23, 59, 59, 999);
Exceptions
|
Improve this Doc
View Source
EndOfMonth(DateTime)
获取月的结束 DateTime (year-month-day 23:59:59.999)
Declaration
public static DateTime EndOfMonth(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 12, 1, 2, 3);
var rs = dt.EndOfMonth(); // 2019-04-30 23:59:59.999
Exceptions
|
Improve this Doc
View Source
EndOfWeek(DateTime, DayOfWeek)
获取本周结束的 DateTime (year-month-day 23:59:59.999)
Declaration
public static DateTime EndOfWeek(this DateTime this, DayOfWeek startOfWeek)
Parameters
Returns
Examples
var dt2 = new DateTime(2019, 4, 1, 1, 2, 3);
var rs2 = dt.EndOfWeek(DayOfWeek.Friday); // 2019-04-04 23:59:59.999
Exceptions
|
Improve this Doc
View Source
EndOfYear(DateTime)
获取年的结束 DateTime (year-month-day 23:59:59.999)
Declaration
public static DateTime EndOfYear(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 12, 1, 2, 3);
var rs = dt.EndOfYear(); // 2019-12-31 23.59.59.999
Exceptions
|
Improve this Doc
View Source
GetTotalDays(DateTime)
Declaration
public static double GetTotalDays(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 11, 11, 11);
dt.GetTotalDays(); // 17987.466099537036
|
Improve this Doc
View Source
GetTotalHours(DateTime)
Declaration
public static double GetTotalHours(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 11, 11, 11);
dt.GetTotalHours(); // 431699.18638888886
|
Improve this Doc
View Source
GetTotalMilliseconds(DateTime)
Declaration
public static double GetTotalMilliseconds(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 11, 11, 11);
dt.GetTotalMilliseconds(); // 1554117071000
|
Improve this Doc
View Source
GetTotalMinutes(DateTime)
Declaration
public static double GetTotalMinutes(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 11, 11, 11);
dt.GetTotalMinutes(); // 25901951.183333334
|
Improve this Doc
View Source
GetTotalSeconds(DateTime)
Declaration
public static double GetTotalSeconds(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 11, 11, 11);
dt.GetTotalSeconds(); // 1554117071
|
Improve this Doc
View Source
IsBetween(DateTime, DateTime, DateTime)
Declaration
public static bool IsBetween(this DateTime this, DateTime startDateTime, DateTime endDateTime)
Parameters
Returns
Examples
var dt = new DateTime(2019,4,1);
var startDate = new DateTime(2019,4,1,0,0,1);
var endDate = new DateTime(2019,5,1);
dt.IsBetween(startDateTime, endDateTime); // false
|
Improve this Doc
View Source
IsToday(DateTime)
Declaration
public static bool IsToday(this DateTime this)
Parameters
Returns
Examples
var dt = DateTime.Now;
dt.IsToday(); // true
var dt2 = new DateTime(2019,1,1);
dt2.IsToday(); // false
|
Improve this Doc
View Source
IsWeekDay(DateTime)
Declaration
public static bool IsWeekDay(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019,5,4);
dt.IsWeekDay(); // false
var dt2 = new DateTime(2019,5,1);
dt2.IsWeekDay(); // true
|
Improve this Doc
View Source
IsZeroTime(DateTime)
Declaration
public static bool IsZeroTime(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 5, 4, 1, 1, 1);
dt.IsZeroTime(); // false
var dt = new DateTime(2019, 5, 4);
dt.IsZeroTime(); // true
|
Improve this Doc
View Source
SetTime(DateTime, Int32, Int32, Int32)
Declaration
public static DateTime SetTime(this DateTime this, int hour, int minute, int second)
Parameters
Returns
Examples
var dt2 = new DateTime(2019, 4, 1, 1, 2, 3);
var rs2 = dt2.SetTime(23, 11, 11, 999);
Exceptions
|
Improve this Doc
View Source
SetTime(DateTime, Int32, Int32, Int32, Int32)
Declaration
public static DateTime SetTime(this DateTime this, int hour, int minute, int second, int millisecond)
Parameters
Returns
Examples
var dt2 = new DateTime(2019, 4, 1, 1, 2, 3);
var rs2 = dt2.SetTime(23, 11, 11, 999);
Exceptions
|
Improve this Doc
View Source
StartOfDay(DateTime)
获取 DateTime 的开始 (year-month-day 00:00:00.000)
Declaration
public static DateTime StartOfDay(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 21, 11, 11, 123);
var rs = dt.StartOfDay(); // rs == new DateTime(2019, 4, 1, 0, 0, 0, 000)
Exceptions
|
Improve this Doc
View Source
StartOfMonth(DateTime)
获取月的开始 DateTime (year-month-day 00:00:00.000)
Declaration
public static DateTime StartOfMonth(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 12, 1, 2, 3);
var rs = dt.StartOfMonth(); // 2019-04-01 00:00:00.000
Exceptions
|
Improve this Doc
View Source
StartOfWeek(DateTime, DayOfWeek)
获取本周开始 DateTime (year-month-day 00:00:00.000)
Declaration
public static DateTime StartOfWeek(this DateTime this, DayOfWeek startOfWeek)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 1, 2, 3);
var rs = dt.StartOfWeek(DayOfWeek.Sunday); // 2019-03-31 00:00:00
Exceptions
|
Improve this Doc
View Source
StartOfYear(DateTime)
获取年的开始 DateTime (year-month-day 00:00:00.000)
Declaration
public static DateTime StartOfYear(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 12, 1, 2, 3);
var rs = dt.StartOfYear(); // 2019-01-01 00:00:00.000
Exceptions
|
Improve this Doc
View Source
Tomorrow(DateTime)
Declaration
public static DateTime Tomorrow(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 5, 4);
var rs = dt.Tomorrow(); // new DateTime(2019, 5, 5);
var dt2 = DateTime.MaxValue; // error -> throw ArgumentOutOfRangeException
Exceptions
|
Improve this Doc
View Source
ToString_Base(DateTime)
Declaration
public static string ToString_Base(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 21, 11, 11, 123);
dt.ToString_Base(); // "2019-04-01 21:11:11"
Exceptions
|
Improve this Doc
View Source
ToString_Day(DateTime)
Declaration
public static string ToString_Day(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 21, 11, 11, 123);
dt.ToString_Day(); // "2019-04-01"
Exceptions
|
Improve this Doc
View Source
ToString_Full(DateTime)
格式化为 yyyy-MM-dd HH:mm:ss.fffffff
Declaration
public static string ToString_Full(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 21, 11, 11, 123);
dt.ToString_Full(); // "2019-04-01 21:11:11.1230000"
Exceptions
|
Improve this Doc
View Source
ToString_Month(DateTime)
Declaration
public static string ToString_Month(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 21, 11, 11, 123);
dt.ToString_Month(); // "2019-04"
Exceptions
|
Improve this Doc
View Source
ToString_ShortDay(DateTime)
Declaration
public static string ToString_ShortDay(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 21, 11, 11, 123);
dt.ToString_ShortDay(); // "19-4-1"
Exceptions
|
Improve this Doc
View Source
ToString_ShortMonth(DateTime)
Declaration
public static string ToString_ShortMonth(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 21, 11, 11, 123);
dt.ToString_ShortMonth(); // "19-4"
Exceptions
|
Improve this Doc
View Source
ToString_ShortTime(DateTime)
格式化为 hh:mm:ss tt
eg. 11:23:02 PM
Declaration
public static string ToString_ShortTime(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 21, 11, 11, 123);
dt.ToString_ShortTime(); // "09:11:11 PM"
Exceptions
|
Improve this Doc
View Source
ToString_ShortYear(DateTime)
Declaration
public static string ToString_ShortYear(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 21, 11, 11, 123);
dt.ToString_ShortYear(); // "19"
Exceptions
|
Improve this Doc
View Source
ToString_Time(DateTime)
Declaration
public static string ToString_Time(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 21, 11, 11, 123);
dt.ToString_Time(); // "21:11:11"
Exceptions
|
Improve this Doc
View Source
ToString_Year(DateTime)
Declaration
public static string ToString_Year(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 4, 1, 21, 11, 11, 123);
dt.ToString_Year(); // "2019"
Exceptions
|
Improve this Doc
View Source
Yesterday(DateTime)
Declaration
public static DateTime Yesterday(this DateTime this)
Parameters
Returns
Examples
var dt = new DateTime(2019, 5, 4, 1, 1, 1);
var rs = dt.Yesterday(); // new DateTime(2019, 5, 3, 1, 1, 1)
var dt2 = DateTime.MinValue; // error -> throw ArgumentOutOfRangeException
Exceptions