Date Formatter isn't showing correct day of the month when using format “DD”How do I get the current Date in short format in SwiftGet Last Day of the Month in PythonHow to subtract a day from a date?Add days to JavaScript DateWhere can I find documentation on formatting a date in JavaScript?jQuery UI DatePicker - Change Date FormatYYYY-MM-DD format date in shell scriptCalculate difference between two dates (number of days)?Get month name from DateConvert date format yyyy-mm-dd => dd-mm-yyyyHow to format a JavaScript date

Why are there yellow dot stickers on the front doors of businesses in Russia?

split inside flalign

How do people drown while wearing a life jacket?

Is a text with orthographic or grammatic mistakes in a language X still a text in that language X?

What printing process is this?

Why does capacitance not depend on the material of the plates?

Repeated! Factorials!

If someone else uploads my GPL'd code to Github without my permission, is that a copyright violation?

C# TCP server/client class

How do I know when and if a character requires a backstory?

Why do my fried eggs start browning very fast?

Awk to get all my regular users in shadow

Can I enter a rental property without giving notice if I'm afraid a tenant may be hurt?

How do I show and not tell a backstory?

Why is it to say 'paucis post diebus'?

What does "autolyco-sentimental" mean?

How to prevent Deadlock on SELECT queries?

ZFS on Linux: Which mountpoint option when mounting manually per script?

Generate random number in Unity without class ambiguity

How can I perform a deterministic physics simulation?

RS-485 network with multiple masters

In MTG, was there ever a five-color deck that worked well?

Did Logical Positivism fail because it simply denied human emotion?

Make lens aperture in Tikz



Date Formatter isn't showing correct day of the month when using format “DD”


How do I get the current Date in short format in SwiftGet Last Day of the Month in PythonHow to subtract a day from a date?Add days to JavaScript DateWhere can I find documentation on formatting a date in JavaScript?jQuery UI DatePicker - Change Date FormatYYYY-MM-DD format date in shell scriptCalculate difference between two dates (number of days)?Get month name from DateConvert date format yyyy-mm-dd => dd-mm-yyyyHow to format a JavaScript date






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-3















I am trying to show today's date as March 26 but it is showing as "March 85" when I use this code.



let formatter = DateFormatter()
formatter.dateFormat = "MMMM DD"
let defaultTimeZoneStr = formatter.string(from: Date())









share|improve this question
































    -3















    I am trying to show today's date as March 26 but it is showing as "March 85" when I use this code.



    let formatter = DateFormatter()
    formatter.dateFormat = "MMMM DD"
    let defaultTimeZoneStr = formatter.string(from: Date())









    share|improve this question




























      -3












      -3








      -3








      I am trying to show today's date as March 26 but it is showing as "March 85" when I use this code.



      let formatter = DateFormatter()
      formatter.dateFormat = "MMMM DD"
      let defaultTimeZoneStr = formatter.string(from: Date())









      share|improve this question
















      I am trying to show today's date as March 26 but it is showing as "March 85" when I use this code.



      let formatter = DateFormatter()
      formatter.dateFormat = "MMMM DD"
      let defaultTimeZoneStr = formatter.string(from: Date())






      swift date time formatter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 4:09









      Cœur

      21.6k10 gold badges126 silver badges173 bronze badges




      21.6k10 gold badges126 silver badges173 bronze badges










      asked Mar 27 at 2:38









      AzaAza

      187 bronze badges




      187 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          3














          The problem is that you are using the wrong date format. D is for "day of year". The correct symbol for "day of month" is lowercased d Thats why you are getting 85instead of 26.



          Another point you should consider is to set your locale fixed to "en_US_POSIX" if you don't want your date string to reflect the users settings and locale.



          Note that you should use Swift native type Date instead of NSDate.



          If your intent is to display it respecting the user locale and settings you should use date formatter dateStyle (short, medium, long or full) How do I get the current Date in short format in Swift



          If you need a localized date format limited to
          month and day only, you can use DateFormatter method dateFormat from template:




          class func dateFormat(fromTemplate tmplate: String, options opts: Int, locale: Locale?) -> String?





          let df = DateFormatter()
          df.dateFormat = DateFormatter.dateFormat(fromTemplate: "MMMMdd", options: 0, locale: .current)
          df.string(from: Date()) // "March 27"





          share|improve this answer


























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368964%2fdate-formatter-isnt-showing-correct-day-of-the-month-when-using-format-dd%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            The problem is that you are using the wrong date format. D is for "day of year". The correct symbol for "day of month" is lowercased d Thats why you are getting 85instead of 26.



            Another point you should consider is to set your locale fixed to "en_US_POSIX" if you don't want your date string to reflect the users settings and locale.



            Note that you should use Swift native type Date instead of NSDate.



            If your intent is to display it respecting the user locale and settings you should use date formatter dateStyle (short, medium, long or full) How do I get the current Date in short format in Swift



            If you need a localized date format limited to
            month and day only, you can use DateFormatter method dateFormat from template:




            class func dateFormat(fromTemplate tmplate: String, options opts: Int, locale: Locale?) -> String?





            let df = DateFormatter()
            df.dateFormat = DateFormatter.dateFormat(fromTemplate: "MMMMdd", options: 0, locale: .current)
            df.string(from: Date()) // "March 27"





            share|improve this answer































              3














              The problem is that you are using the wrong date format. D is for "day of year". The correct symbol for "day of month" is lowercased d Thats why you are getting 85instead of 26.



              Another point you should consider is to set your locale fixed to "en_US_POSIX" if you don't want your date string to reflect the users settings and locale.



              Note that you should use Swift native type Date instead of NSDate.



              If your intent is to display it respecting the user locale and settings you should use date formatter dateStyle (short, medium, long or full) How do I get the current Date in short format in Swift



              If you need a localized date format limited to
              month and day only, you can use DateFormatter method dateFormat from template:




              class func dateFormat(fromTemplate tmplate: String, options opts: Int, locale: Locale?) -> String?





              let df = DateFormatter()
              df.dateFormat = DateFormatter.dateFormat(fromTemplate: "MMMMdd", options: 0, locale: .current)
              df.string(from: Date()) // "March 27"





              share|improve this answer





























                3












                3








                3







                The problem is that you are using the wrong date format. D is for "day of year". The correct symbol for "day of month" is lowercased d Thats why you are getting 85instead of 26.



                Another point you should consider is to set your locale fixed to "en_US_POSIX" if you don't want your date string to reflect the users settings and locale.



                Note that you should use Swift native type Date instead of NSDate.



                If your intent is to display it respecting the user locale and settings you should use date formatter dateStyle (short, medium, long or full) How do I get the current Date in short format in Swift



                If you need a localized date format limited to
                month and day only, you can use DateFormatter method dateFormat from template:




                class func dateFormat(fromTemplate tmplate: String, options opts: Int, locale: Locale?) -> String?





                let df = DateFormatter()
                df.dateFormat = DateFormatter.dateFormat(fromTemplate: "MMMMdd", options: 0, locale: .current)
                df.string(from: Date()) // "March 27"





                share|improve this answer















                The problem is that you are using the wrong date format. D is for "day of year". The correct symbol for "day of month" is lowercased d Thats why you are getting 85instead of 26.



                Another point you should consider is to set your locale fixed to "en_US_POSIX" if you don't want your date string to reflect the users settings and locale.



                Note that you should use Swift native type Date instead of NSDate.



                If your intent is to display it respecting the user locale and settings you should use date formatter dateStyle (short, medium, long or full) How do I get the current Date in short format in Swift



                If you need a localized date format limited to
                month and day only, you can use DateFormatter method dateFormat from template:




                class func dateFormat(fromTemplate tmplate: String, options opts: Int, locale: Locale?) -> String?





                let df = DateFormatter()
                df.dateFormat = DateFormatter.dateFormat(fromTemplate: "MMMMdd", options: 0, locale: .current)
                df.string(from: Date()) // "March 27"






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 27 at 11:17

























                answered Mar 27 at 3:34









                Leo DabusLeo Dabus

                147k35 gold badges316 silver badges387 bronze badges




                147k35 gold badges316 silver badges387 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368964%2fdate-formatter-isnt-showing-correct-day-of-the-month-when-using-format-dd%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript