相关文章推荐
高大的洋葱  ·  aes_encrypt 函数 - ...·  6 月前    · 
精彩文章免费看

laravel中Carbon包的使用详解

介绍

Carbon 是对 PHP DateTime 模块的二次扩展;提供时间格式化,时间计算的功能;

  • 官方主页为 http://carbon.nesbot.com/ ;

  • Github 地址为 https://github.com/briannesbitt/Carbon ;

  • year(null), month(null), day(null), hour(null), minute(null), second(null), $tz(null) 根据日期和时间创建 Carbon 实例 如果指定参数为 null ,会默认使用当前时间的对应值 createSafe(static) year(null), month(null), day(null), hour(null), minute(null), second(null), $tz(null) 根据日期和时间创建 Carbon 实例 如果指定参数为 null ,会默认使用当前时间的对应值; 指定参数不符合规范,会返回异常; createFromDate(static) year(null), month(null), day(null), tz(null) 根据日期创建 Carbon 实例如果指定参数为 null ,会默认使用当前时间的对应值 createFromTime(static) hour(null), minute(null), minute(null), tz(null) 根据时间创建 Carbon 实例如果指定参数为 null ,会默认使用当前时间的对应值 createFromFormat(static) format, time, $tz(null) 根据时间字符串及其对应的 format 字符串创建 Carbon 实例 createFromTimestamp(static) timestamp, tz(null) 根据时间戳和指定时区, 创建 Carbon 实例 createFromTimestampUTC(static) $timestamp 根据时间戳和 utc 时区, 创建 Carbon 实例 now(static) $tx(null) 根据当前时间创建 Carbon 实例 today(static) $tx(null) 根据当前时间创建 Carbon 实例,时间重置为 0时0分0秒 tomorrow(static) $tx(null) 根据当前时间,加一天,创建 Carbon 实例 yesterday(static) $tx(null) 根据当前时间, 减一天, 创建 Carbon 实例 minValue(static) 创建系统支持的最小时间,并返回 Carbon 实例 maxValue(static) 创建系统支持的最大时间,并返回 Carbon 实例 复制当前 Carbon 实例 fromSerialized(static) $value 解析序列化字符串,创建 Carbon 实例

    用途:修改 Carbon 实例

    between Carbon dt1, Carbon dt2, $equal(true) 判断当前 Carbon 实例是否在指定 Carbon 对象时间之间, 第三个参数表示是否可以等于指定 Carbon 对象 Carbon $dt 获取当前实例与指定 Carbon 对象中,最小的对象 minimum Carbon $dt 同 min Carbon $dt 获取当前实例与指定 Carbon 对象中,最大的对象 maximum Carbon $dt 同 max closest Carbon dt1, Carbon dt2 获取最接近当前实例时间的 Carbon 对象 farthest Carbon dt1, Carbon dt2 获取最不接近当前实例时间的 Carbon 对象 isSameAs 判断当前实例与指定 Carbon 对象的 format 格式化结果是否相同 isSameDay Carbon $dt 判断当前实例与指定 Carbon 对象是否是同一天 isSameMonth Carbon dt(null), ofSameYear(false) 判断当前实例与指定 Carbon 对象月份是否相同 isBirthday Carbon $dt 判断当前实例与指定 Carbon 对象月日数是否相同 isSameYear Carbon $dt 判断当前实例与指定 Carbon 对象年份是否相同 isSunday 判断当前实例是否是周日 isMonday 判断当前实例是否是周一 isTuesday 判断当前实例是否是周二 isWednesday 判断当前实例是否是周三 isThursday 判断当前实例是否是周四 isFriday 判断当前实例是否是周五 isSaturday 判断当前实例是否是周六 isYesterday 判断当前实例是否是昨天 isToday 判断当前实例是否是今天 isTomorrow 判断当前实例是否是明天 isWeekday 判断当前实例是否属于工作日 isWeekend 判断当前实例是否属于周末双休 isLastWeek 判断当前实例是否属于上周 isNextWeek 判断当前实例是否属于下一周 isLastMonth 判断当前实例是否属于上一个月 isCurrentMonth 判断当前实例是否属于当前月 isNextMonth 判断当前实例是否属于下一个月 isLastYear 判断当前实例是否属于去年 isCurrentYear 判断当前实例是否属于当前年 isNextYear 判断当前实例是否属于下一年 isLeapYear 判断当前实例是否属于闰年 isLongYear 判断当前实例是否属于长年,即一年不只有52个星期 isPast 判断当前实例是否属于过去 isFuture 判断当前实例是否属于未来

    用途:时间计算

    diffFiltered CarbonInterval ci, Closure callback, Carbon dt(null), abs(true) 获取指定 Carbon 对象与当前实例时间的(通过回调函数较验的) $ci 差, 取整 diffForHumans Carbon other(null), absolute(false), $short(false) 获取指定 Carbon 对象与当前实例时间的时间差,以便于人类阅读的格式呈现

    用途:Getter & Setter