quattro_4 scribble

scribble 落書き (調べた事をただ落書きする)

MotionInMotion Episode 19 - Dates with MHPrettyDate, NSCalendar, and NSDateComponents

Dates with MHPrettyDate, NSCalendar, and NSDateComponents - MotionInMotion

Taskアプリで日付の表示を変更

  • MHPrettyDate
    • get "Pretty Dates" ("Yesterday", "Today", etc.)
    • DueAtLabel
      • configure
        • MHPrettyDate.prettyDateFromDate(data[:due_at], withFormat: MHPrettyDateFormatWithTime)
        • MHPrettyDate.isPastTime(data[:due_at])
          • self.textColor = UIColor.redColor
  • NSCalendar & NSDateComponents
============================================
==== NSCalendar & NSDateComponents Demo ====
============================================

What type of calendar?
# calendar.calendarIdentifier
gregorian

What timezone?
# calendar.timeZone.name
Asia/Tokyo

Get the year, month, day, hour, minute, and second
#    components = calendar.components(
#      NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit |
#      NSMinuteCalendarUnit | NSSecondCalendarUnit,
#      fromDate: Time.now
#    )
Year:   2014
Month:  4
Day:    17
Hour:   21
Minute: 45
Second: 55

Special calendar units
#    components = calendar.components(
#      NSWeekCalendarUnit | NSWeekdayCalendarUnit | NSWeekdayOrdinalCalendarUnit |
#      NSQuarterCalendarUnit | NSWeekOfMonthCalendarUnit | NSWeekOfYearCalendarUnit |
#      NSEraCalendarUnit,
#      fromDate: Time.now
#    )
Week:            16
Weekday:         5
Weekday Ordinal: 3
Quarter:         0
Week of Month:   3
Week of Year:    16
Era:             1

Add components to date
# future = calendar.dateByAddingComponents(components, toDate: Time.now, options: 0)
Now: 2014-04-17 21:45:55 +0900
Then: 2024-05-22 21:45:55 +0900