20200714--iOS之DateFormatter类,日期格式化器

DateFormatter是iOS中用于日期和时间文本表示转换的类,它支持用户可见的日期时间格式和固定格式的日期表示。通过设置dateStyle和timeStyle属性,可以定制适合特定语言环境的日期格式。在ISO 8601格式下,推荐使用ISO8601DateFormatter。线程安全方面,在iOS 7及以上版本中,DateFormatter是线程安全的。
摘要由CSDN通过智能技术生成

Class

DateFormatter

A formatter that converts between dates and their textual representations.

--在日期及其文本表示形式之间进行转换的格式化程序。将date作为formatter的参数进行格式化输出

 

Declaration         --声明

class DateFormatter : Formatter

Overview         --概览

Instances of DateFormatter create string representations of NSDate objects, and convert textual representations of dates and times into NSDate objects. For user-visible representations of dates and times, DateFormatter provides a variety of localized presets and configuration options. For fixed format representations of dates and times, you can specify a custom format string.

--DateFormatter的实例创建NSDate对象的字符串表示,并将日期和时间的文本表示转换NSDate对象。对于用户可见的日期和时间表示,DateFormatter提供了各种本地化预置和配置选项。对于日期和时间的固定格式表示,可以指定自定义格式字符串。

 

When working with date representations in ISO 8601 format, use ISO8601DateFormatter instead.

--使用ISO8601格式的日期表示时,请使用ISO8601DateFormatter。

To represent an interval between two NSDate objects, use DateIntervalFormatter instead.

--要表示两个NSDate对象之间的间隔,请使用DateIntervalFormatter代替

To represent a quantity of time specified by an NSDateComponents object, use DateComponentsFormatter instead.

--要表示NSDateComponents对象指定的时间量,请使用DateComponentsFormatter。

 

Working With User-Visible Representations of Dates and Times      

  --使用用户可见的日期和时间表示

 

When displaying a date to a user, you set the dateStyle and timeStyle properties of the date formatter according to your particular needs. For example, if you want to show the month, day, and year without showing the time, you would set the dateStyle property to DateFormatter.Style.long and the timeStyle property to DateFormatter.Style.none. Conversely, if you want to show only the time, you would set the dateStyle property to DateFormatter.Style.none and the timeStyle property to DateFormatter.Style.short. Based on the values of the dateStyle and timeStyle

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值