NSDate(FWFoundation)

@interface NSDate (FWFoundation)

/// 转化为字符串,默认当前时区,格式:yyyy-MM-dd HH:mm:ss
@property (nonatomic, copy, readonly) NSString *fw_stringValue NS_REFINED_FOR_SWIFT;

/// 转化为字符串,默认当前时区,自定义格式
- (NSString *)fw_stringWithFormat:(NSString *)format NS_REFINED_FOR_SWIFT;

/// 转化为字符串,自定义格式和时区
- (NSString *)fw_stringWithFormat:(NSString *)format timeZone:(nullable NSTimeZone *)timeZone NS_REFINED_FOR_SWIFT;

/// 当前时间戳,没有设置过返回本地时间戳,可同步设置服务器时间戳,同步后调整手机时间不影响
@property (class, nonatomic, assign) NSTimeInterval fw_currentTime NS_REFINED_FOR_SWIFT;

/// 从字符串初始化日期,默认当前时区,格式:yyyy-MM-dd HH:mm:ss
+ (nullable NSDate *)fw_dateWithString:(NSString *)string NS_REFINED_FOR_SWIFT;

/// 从字符串初始化日期,默认当前时区,自定义格式
+ (nullable NSDate *)fw_dateWithString:(NSString *)string format:(NSString *)format NS_REFINED_FOR_SWIFT;

/// 从字符串初始化日期,自定义格式和时区
+ (nullable NSDate *)fw_dateWithString:(NSString *)string format:(NSString *)format timeZone:(nullable NSTimeZone *)timeZone NS_REFINED_FOR_SWIFT;

/// 格式化时长,格式"00:00"或"00:00:00"
+ (NSString *)fw_formatDuration:(NSTimeInterval)duration hasHour:(BOOL)hasHour NS_REFINED_FOR_SWIFT;

/// 格式化16位、13位时间戳为10位(秒)
+ (NSTimeInterval)fw_formatTimestamp:(NSTimeInterval)timestamp NS_REFINED_FOR_SWIFT;

/// 是否是闰年
@property (nonatomic, assign, readonly) BOOL fw_isLeapYear NS_REFINED_FOR_SWIFT;

/// 是否是同一天
- (BOOL)fw_isSameDay:(NSDate *)date NS_REFINED_FOR_SWIFT;

/// 添加指定日期,如year:1|month:-1|day:1等
- (nullable NSDate *)fw_dateByAdding:(NSDateComponents *)components NS_REFINED_FOR_SWIFT;

/// 与指定日期相隔天数
- (NSInteger)fw_daysFrom:(NSDate *)date NS_REFINED_FOR_SWIFT;

@end

Undocumented

  • 转化为字符串,默认当前时区,格式:yyyy-MM-dd HH:mm:ss

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSString *fw_stringValue;
  • 转化为字符串,默认当前时区,自定义格式

    Declaration

    Objective-C

    - (nonnull NSString *)fw_stringWithFormat:(nonnull NSString *)format;
  • 转化为字符串,自定义格式和时区

    Declaration

    Objective-C

    - (nonnull NSString *)fw_stringWithFormat:(nonnull NSString *)format
                                     timeZone:(nullable NSTimeZone *)timeZone;
  • 当前时间戳,没有设置过返回本地时间戳,可同步设置服务器时间戳,同步后调整手机时间不影响

    Declaration

    Objective-C

    @property (class, nonatomic) NSTimeInterval fw_currentTime;
  • 从字符串初始化日期,默认当前时区,格式:yyyy-MM-dd HH:mm:ss

    Declaration

    Objective-C

    + (nullable NSDate *)fw_dateWithString:(nonnull NSString *)string;
  • 从字符串初始化日期,默认当前时区,自定义格式

    Declaration

    Objective-C

    + (nullable NSDate *)fw_dateWithString:(nonnull NSString *)string
                                    format:(nonnull NSString *)format;
  • 从字符串初始化日期,自定义格式和时区

    Declaration

    Objective-C

    + (nullable NSDate *)fw_dateWithString:(nonnull NSString *)string
                                    format:(nonnull NSString *)format
                                  timeZone:(nullable NSTimeZone *)timeZone;
  • 格式化时长,格式"00:00"或"00:00:00"

    Declaration

    Objective-C

    + (nonnull NSString *)fw_formatDuration:(NSTimeInterval)duration
                                    hasHour:(BOOL)hasHour;
  • 格式化16位、13位时间戳为10位(秒)

    Declaration

    Objective-C

    + (NSTimeInterval)fw_formatTimestamp:(NSTimeInterval)timestamp;
  • 是否是闰年

    Declaration

    Objective-C

    @property (nonatomic, readonly) BOOL fw_isLeapYear;
  • 是否是同一天

    Declaration

    Objective-C

    - (BOOL)fw_isSameDay:(nonnull NSDate *)date;
  • 添加指定日期,如year:1|month:-1|day:1等

    Declaration

    Objective-C

    - (nullable NSDate *)fw_dateByAdding:(nonnull NSDateComponents *)components;
  • 与指定日期相隔天数

    Declaration

    Objective-C

    - (NSInteger)fw_daysFrom:(nonnull NSDate *)date;