Upgrade to Pro — share decks privately, control downloads, hide ads and more …

20161226 日付のあれこれ

Kei Ito
December 26, 2016

20161226 日付のあれこれ

関モバ #21の資料です

Kei Ito

December 26, 2016
Tweet

More Decks by Kei Ito

Other Decks in Programming

Transcript

  1. let formatter = DateFormatter() formatter.locale = Locale(identifier: "ja_JP") formatter.setLocalizedDateFormatFromTemplate("yMMMMd") formatter.string(from:

    date) // 2016೥12݄26೔ let formatter = DateFormatter() formatter.locale = Locale(identifier: “fr_FR") formatter.setLocalizedDateFormatFromTemplate("yMMMMd") formatter.string(from: date) // 26 décembre 2016 let formatter = DateFormatter() formatter.locale = Locale(identifier: "ja_JP") formatter.calendar = Calendar(identifier: .japanese) formatter.setLocalizedDateFormatFromTemplate("GyMd") formatter.string(from: date) // ฏ੒28೥12݄26೔ %BUF'PSNBUUFS
  2. let formatter = ISO8601DateFormatter() formatter.string(from: date) // 2016-12-26T04:23:50Z formatter.formatOptions =

    [.withFullDate, .withFullTime, .withSpaceBetweenDateAndTime] formatter.string(from: date) // 2016-12-26 04:23:50Z *40%BUF'PSNBUUFS
  3. let formatter = DateIntervalFormatter() formatter.string(from: now, to: future) // 2016/12/26

    19࣌00෼ʙ21࣌00෼ formatter.dateTemplate = "Hm" formatter.string(from: now, to: future) // 19࣌00෼ʙ21࣌00෼ %BUF*OUFSWBM'PSNBUUFS
  4. %BUF$PNQPOFOUT'PSNBUUFS let formatter = DateComponentsFormatter() formatter.string(from: now, to: future) //

    1೔ 5:27:50 formatter.allowedUnits = [.hour, .minute] formatter.string(from: now, to: future) // 29:27 comp.includesApproximationPhrase = true comp.string(from: now, to: future) // About 29:27
  5. let interval = DateInterval(start: date, end: future) intervalFormatter.string(from: interval) //

    2016/12/26 19࣌00෼ʙ21࣌00෼ ॏͳ͍ͬͯΔ͔ interval.intersects(interval2) // ॏͳΓ෦෼Λநग़ interval.intersection(with: interval2) %BUF*OUFSWBM