Uploaded image for project: 'Swift'
  1. Swift
  2. SR-208

Setting .dateFormat of NSDateFormatter has no effect

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Foundation
    • Labels:
      None
    • Environment:

      Ubuntu 14.04 with
      Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c)
      Target: x86_64-unknown-linux-gnu

      Description

      The following code:

      import Foundation
      
      let dateFormatter = NSDateFormatter()
      dateFormatter.dateFormat = String("dd-MM-yyyy")
      var dateStr = dateFormatter.stringFromDate(NSDate())
      
      print("With dateFormat '\(dateFormatter.dateFormat)':  '\(dateStr)'")
      
      dateFormatter.dateStyle = .MediumStyle
      dateFormatter.timeStyle = .MediumStyle
      dateStr = dateFormatter.stringFromDate(NSDate())
      print("With dateStyle and timeStyle set to .MediumStyle:  '\(dateStr)'")
      

      should result in

      With dateFormat 'dd-MM-yyyy':  '12-12-2015'
      With dateStyle and timeStyle set to .MediumStyle:  'Dec 12, 2015, 9:46:33 PM'
      

      Instead it results in:

      With dateFormat 'dd-MM-yyyy':  ''
      With dateStyle and timeStyle set to .MediumStyle:  'Dec 12, 2015, 9:46:33 PM'
      

      It appears that setting the dateFormat property of a NSDateFormatter instance has no effect.

        Attachments

          Activity

            People

            • Assignee:
              tfrank64 Taylor Franklin
              Reporter:
              joeiachievedit Joe
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: