DateTimeUtils class

日期时间工具类

Constructors

DateTimeUtils()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

copyWith(DateTime date, {int? year, int? month, int? day, int? hour, int? minute, int? second, int? millisecond, int? microsecond}) DateTime
firstDayOfMonth(DateTime date) DateTime
Returns DateTime that represents a beginning of the first day of the month containing date.
firstDayOfNextMonth(DateTime dateTime) DateTime
Returns DateTime that represents a beginning of the first day of the next month.
firstDayOfNextYear(DateTime dateTime) DateTime
Returns DateTime that represents a beginning of the first day of the next year.
firstDayOfYear(DateTime dateTime) DateTime
Returns DateTime that represents a beginning of the first day of the year containing date.
formatDate(DateTime dateTime, {String? format}) String
format 转换格式(已提供常用格式 DateTimeFormats,可以自定义格式:'yyyy/MM/dd HH:mm:ss')
formatDateMilliseconds(int ms, {bool isUtc = false, String? format}) String
格式化日期毫秒时间
formatDateString(String dateStr, {bool isUtc = false, String? format}) String
格式化日期字符串
generateWithDayStep(DateTime start, DateTime end) Iterable<DateTime>
Returns an iterable of DateTime with 1 day step in given range.
getDateMsByTimeString(String dateStr, {bool isUtc = false}) int
将字符串时间转化为毫秒值
getDateTime(String dateStr, {bool isUtc = false}) DateTime
将字符串时间转化为DateTime,如果解析失败则返回当前时间
getDateTimeByMs(int ms, {bool isUtc = false}) DateTime
将毫秒时间转化为DateTime
getDateTimeFormat(String dateStr, {bool isUtc = false, String format = 'yyyy-MM-dd HH:mm:ss'}) String
获取日期字符串或指定格式的日期时间,可以指定是否返回UTC时间
getDayOfYear(DateTime dateTime) int
get day of year. 在今年的第几天.
getDayOfYearByMilliseconds(int ms, {bool isUtc = false}) int
get day of year. 在今年的第几天.
getDaysInMonth(int year, int monthNum) int
Returns number of days in the month of the year.
getNowDateMs() int
获取当前毫秒值
getNowDateTime({bool isUtc = false}) DateTime
获取当前日期返回DateTime,可以指定是否返回UTC时间
getNowDateTimeFormat(String outFormat) String
获取当前日期,返回指定格式
getNowUtcDateTime() DateTime
获取当前日期返回DateTime(utc)
getUtcDateTimeFormat(String outFormat) String
获取当前日期,返回指定格式
getWeekday(DateTime dateTime, {String languageCode = 'zh', bool short = false}) String
get WeekDay. 获取dateTime是星期几
getWeekdayByMilliseconds(int milliseconds, {bool isUtc = false, String languageCode = 'en', bool short = false}) String
get WeekDay By Milliseconds. 获取毫秒值对应是星期几
isCurrentDate(DateTime date) bool
Проверяет является ли заданная дата текущей.
isLeapYear(DateTime dateTime) bool
Return whether it is leap year. 是否是闰年
isLeapYearByMilliseconds(int milliseconds) bool
Return whether it is leap year. 是否是闰年
isLeapYearByYear(int year) bool
Return whether it is leap year. 是否是闰年
isSameDay(DateTime a, DateTime b) bool
判断a和b两个时间是否是同一天
isToday(int milliseconds, {bool isUtc = false, int? locMs}) bool
is today. 根据时间戳判断是否是今天
isYesterday(DateTime dateTime, DateTime locDateTime) bool
is yesterday by dateTime. 根据时间判断是否是昨天
isYesterdayByMilliseconds(int ms, int locMs) bool
is yesterday by millis. 是否是昨天.
lastDayOfMonth(DateTime dateTime) DateTime
Returns DateTime that represents a beginning of the last day of the month containing date.
lastDayOfYear(DateTime dateTime) DateTime
Returns DateTime that represents a beginning of the last day of the year containing date.
nextDay(DateTime d) DateTime
Returns same time in the next day.
nextMonth(DateTime date) int
Returns a number of the next month.
nextYear(DateTime d) DateTime
Returns same date in the next year.
previousDay(DateTime d) DateTime
Returns same time in the previous day.
previousYear(DateTime d) DateTime
Returns same date in the previous year.
setTime(DateTime date, int hours, int minutes, [int seconds = 0, int milliseconds = 0, int microseconds = 0]) DateTime
Creates a copy of date but with time replaced with the new values.
startOfDay(DateTime dateTime) DateTime
Returns DateTime for the beginning of the day (00:00:00).
startOfNextDay(DateTime dateTime) DateTime
Returns DateTime for the beginning of the next day (00:00:00).
startOfToday() DateTime
Returns DateTime for the beginning of today (00:00:00).
yearIsEqual(DateTime dateTime, DateTime locDateTime) bool
year is equal. 是否同年.
yearIsEqualByMilliseconds(int ms, int locMs) bool
year is equal. 是否同年.