Format date from “yyyy-mm-ddTHH:mm:ss.SSS” to human readable format using angular 2












0















I have a JSON data in the below format and want to display the startDateTime in human readable format.



  var txns = {    
"payeeAccNum": "12081031991",
"startDateTime": "2018-11-13T20:47:47.866"
}


I have done in the following way, but it always showing time as 12:00:00 AM only. can any one help on this?



<span [innerHTML]="(txns.startDateTime | date:'d MMM yyyy h:mm:ss a')"></span>









share|improve this question



























    0















    I have a JSON data in the below format and want to display the startDateTime in human readable format.



      var txns = {    
    "payeeAccNum": "12081031991",
    "startDateTime": "2018-11-13T20:47:47.866"
    }


    I have done in the following way, but it always showing time as 12:00:00 AM only. can any one help on this?



    <span [innerHTML]="(txns.startDateTime | date:'d MMM yyyy h:mm:ss a')"></span>









    share|improve this question

























      0












      0








      0








      I have a JSON data in the below format and want to display the startDateTime in human readable format.



        var txns = {    
      "payeeAccNum": "12081031991",
      "startDateTime": "2018-11-13T20:47:47.866"
      }


      I have done in the following way, but it always showing time as 12:00:00 AM only. can any one help on this?



      <span [innerHTML]="(txns.startDateTime | date:'d MMM yyyy h:mm:ss a')"></span>









      share|improve this question














      I have a JSON data in the below format and want to display the startDateTime in human readable format.



        var txns = {    
      "payeeAccNum": "12081031991",
      "startDateTime": "2018-11-13T20:47:47.866"
      }


      I have done in the following way, but it always showing time as 12:00:00 AM only. can any one help on this?



      <span [innerHTML]="(txns.startDateTime | date:'d MMM yyyy h:mm:ss a')"></span>






      angularjs






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 16:24









      vishnuvishnu

      1,48693158




      1,48693158
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Using the date filter you can format your date/time to any format you need to:




          'medium': equivalent to 'MMM d, y h:mm:ss a' for en_US locale (e.g. Sep 3, 2010 12:05:08 PM)



          'short': equivalent to 'M/d/yy h:mm a' for en_US locale (e.g. 9/3/10
          12:05 PM)



          'fullDate': equivalent to 'EEEE, MMMM d, y' for en_US locale
          (e.g. Friday, September 3, 2010)



          'shortDate': equivalent to 'M/d/yy' for en_US locale (e.g. 9/3/10)



          'mediumTime': equivalent to 'h:mm:ss a' for en_US locale (e.g.
          12:05:08 PM)



          'shortTime': equivalent to 'h:mm a' for en_US locale
          (e.g. 12:05 PM)




          Now what format do you want your time to be displayed in?



          for Medium display, use:



          <span [innerHTML]="(txns.startDateTime |  date:'medium')"></span>


          and it's better if you use [innerText] in stead of HTML for span contents.



          to get something like medium date without seconds use 'MMM d, y h:mm a'



          Dateoffset filter:



          transform(value: any, format = 'MM/dd/yyyy'): string {
          let formattedDt: string;
          if (value) {
          if (DateUtil.DATE_TIMEZONE_REGEX.test(value)) {
          value = this.removeTimezone(value);
          }
          formattedDt = this.datePipe.transform(new Date(value), format);
          }
          return formattedDt;
          }

          private removeTimezone(value: any): string {
          const timezoneDashIndex = value.lastIndexOf('-');
          return value.slice(0, timezoneDashIndex);
          }





          share|improve this answer


























          • I want to display the date and time in 'Medium' format. can you please help on this

            – vishnu
            Nov 13 '18 at 17:05











          • I tried like this, (txns.startDateTime | date:'medium'), but still it showing time as 12:00:00 AM.

            – vishnu
            Nov 13 '18 at 17:09











          • @vishnu , what is your desired output? medium will show date time like this: Sep 3, 2010 12:05:08 PM, so 12:00:00AM is fine, If you do not want seconds, use 'short'. for getting just time use 'shortTime'

            – nircraft
            Nov 13 '18 at 17:12













          • I am getting the response from server is, '2018-11-13T20:47:47.866'. I want to show like Nov 13, 2018 08:47 PM

            – vishnu
            Nov 13 '18 at 17:15











          • @vishnu, then you should use 'MMM d, y h:mm a' as your filter format. hope it helps. I have updated my answer for you to accept.

            – nircraft
            Nov 13 '18 at 17:17





















          0














          consider using moment.js library for datatime conversions



          visit momentjs.com



          for your code this is the solution:




          var requiredDateFormat= moment(tsnx.startDateTime).format('MM-DD-YYYY')







          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%2f53285324%2fformat-date-from-yyyy-mm-ddthhmmss-sss-to-human-readable-format-using-angula%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Using the date filter you can format your date/time to any format you need to:




            'medium': equivalent to 'MMM d, y h:mm:ss a' for en_US locale (e.g. Sep 3, 2010 12:05:08 PM)



            'short': equivalent to 'M/d/yy h:mm a' for en_US locale (e.g. 9/3/10
            12:05 PM)



            'fullDate': equivalent to 'EEEE, MMMM d, y' for en_US locale
            (e.g. Friday, September 3, 2010)



            'shortDate': equivalent to 'M/d/yy' for en_US locale (e.g. 9/3/10)



            'mediumTime': equivalent to 'h:mm:ss a' for en_US locale (e.g.
            12:05:08 PM)



            'shortTime': equivalent to 'h:mm a' for en_US locale
            (e.g. 12:05 PM)




            Now what format do you want your time to be displayed in?



            for Medium display, use:



            <span [innerHTML]="(txns.startDateTime |  date:'medium')"></span>


            and it's better if you use [innerText] in stead of HTML for span contents.



            to get something like medium date without seconds use 'MMM d, y h:mm a'



            Dateoffset filter:



            transform(value: any, format = 'MM/dd/yyyy'): string {
            let formattedDt: string;
            if (value) {
            if (DateUtil.DATE_TIMEZONE_REGEX.test(value)) {
            value = this.removeTimezone(value);
            }
            formattedDt = this.datePipe.transform(new Date(value), format);
            }
            return formattedDt;
            }

            private removeTimezone(value: any): string {
            const timezoneDashIndex = value.lastIndexOf('-');
            return value.slice(0, timezoneDashIndex);
            }





            share|improve this answer


























            • I want to display the date and time in 'Medium' format. can you please help on this

              – vishnu
              Nov 13 '18 at 17:05











            • I tried like this, (txns.startDateTime | date:'medium'), but still it showing time as 12:00:00 AM.

              – vishnu
              Nov 13 '18 at 17:09











            • @vishnu , what is your desired output? medium will show date time like this: Sep 3, 2010 12:05:08 PM, so 12:00:00AM is fine, If you do not want seconds, use 'short'. for getting just time use 'shortTime'

              – nircraft
              Nov 13 '18 at 17:12













            • I am getting the response from server is, '2018-11-13T20:47:47.866'. I want to show like Nov 13, 2018 08:47 PM

              – vishnu
              Nov 13 '18 at 17:15











            • @vishnu, then you should use 'MMM d, y h:mm a' as your filter format. hope it helps. I have updated my answer for you to accept.

              – nircraft
              Nov 13 '18 at 17:17


















            0














            Using the date filter you can format your date/time to any format you need to:




            'medium': equivalent to 'MMM d, y h:mm:ss a' for en_US locale (e.g. Sep 3, 2010 12:05:08 PM)



            'short': equivalent to 'M/d/yy h:mm a' for en_US locale (e.g. 9/3/10
            12:05 PM)



            'fullDate': equivalent to 'EEEE, MMMM d, y' for en_US locale
            (e.g. Friday, September 3, 2010)



            'shortDate': equivalent to 'M/d/yy' for en_US locale (e.g. 9/3/10)



            'mediumTime': equivalent to 'h:mm:ss a' for en_US locale (e.g.
            12:05:08 PM)



            'shortTime': equivalent to 'h:mm a' for en_US locale
            (e.g. 12:05 PM)




            Now what format do you want your time to be displayed in?



            for Medium display, use:



            <span [innerHTML]="(txns.startDateTime |  date:'medium')"></span>


            and it's better if you use [innerText] in stead of HTML for span contents.



            to get something like medium date without seconds use 'MMM d, y h:mm a'



            Dateoffset filter:



            transform(value: any, format = 'MM/dd/yyyy'): string {
            let formattedDt: string;
            if (value) {
            if (DateUtil.DATE_TIMEZONE_REGEX.test(value)) {
            value = this.removeTimezone(value);
            }
            formattedDt = this.datePipe.transform(new Date(value), format);
            }
            return formattedDt;
            }

            private removeTimezone(value: any): string {
            const timezoneDashIndex = value.lastIndexOf('-');
            return value.slice(0, timezoneDashIndex);
            }





            share|improve this answer


























            • I want to display the date and time in 'Medium' format. can you please help on this

              – vishnu
              Nov 13 '18 at 17:05











            • I tried like this, (txns.startDateTime | date:'medium'), but still it showing time as 12:00:00 AM.

              – vishnu
              Nov 13 '18 at 17:09











            • @vishnu , what is your desired output? medium will show date time like this: Sep 3, 2010 12:05:08 PM, so 12:00:00AM is fine, If you do not want seconds, use 'short'. for getting just time use 'shortTime'

              – nircraft
              Nov 13 '18 at 17:12













            • I am getting the response from server is, '2018-11-13T20:47:47.866'. I want to show like Nov 13, 2018 08:47 PM

              – vishnu
              Nov 13 '18 at 17:15











            • @vishnu, then you should use 'MMM d, y h:mm a' as your filter format. hope it helps. I have updated my answer for you to accept.

              – nircraft
              Nov 13 '18 at 17:17
















            0












            0








            0







            Using the date filter you can format your date/time to any format you need to:




            'medium': equivalent to 'MMM d, y h:mm:ss a' for en_US locale (e.g. Sep 3, 2010 12:05:08 PM)



            'short': equivalent to 'M/d/yy h:mm a' for en_US locale (e.g. 9/3/10
            12:05 PM)



            'fullDate': equivalent to 'EEEE, MMMM d, y' for en_US locale
            (e.g. Friday, September 3, 2010)



            'shortDate': equivalent to 'M/d/yy' for en_US locale (e.g. 9/3/10)



            'mediumTime': equivalent to 'h:mm:ss a' for en_US locale (e.g.
            12:05:08 PM)



            'shortTime': equivalent to 'h:mm a' for en_US locale
            (e.g. 12:05 PM)




            Now what format do you want your time to be displayed in?



            for Medium display, use:



            <span [innerHTML]="(txns.startDateTime |  date:'medium')"></span>


            and it's better if you use [innerText] in stead of HTML for span contents.



            to get something like medium date without seconds use 'MMM d, y h:mm a'



            Dateoffset filter:



            transform(value: any, format = 'MM/dd/yyyy'): string {
            let formattedDt: string;
            if (value) {
            if (DateUtil.DATE_TIMEZONE_REGEX.test(value)) {
            value = this.removeTimezone(value);
            }
            formattedDt = this.datePipe.transform(new Date(value), format);
            }
            return formattedDt;
            }

            private removeTimezone(value: any): string {
            const timezoneDashIndex = value.lastIndexOf('-');
            return value.slice(0, timezoneDashIndex);
            }





            share|improve this answer















            Using the date filter you can format your date/time to any format you need to:




            'medium': equivalent to 'MMM d, y h:mm:ss a' for en_US locale (e.g. Sep 3, 2010 12:05:08 PM)



            'short': equivalent to 'M/d/yy h:mm a' for en_US locale (e.g. 9/3/10
            12:05 PM)



            'fullDate': equivalent to 'EEEE, MMMM d, y' for en_US locale
            (e.g. Friday, September 3, 2010)



            'shortDate': equivalent to 'M/d/yy' for en_US locale (e.g. 9/3/10)



            'mediumTime': equivalent to 'h:mm:ss a' for en_US locale (e.g.
            12:05:08 PM)



            'shortTime': equivalent to 'h:mm a' for en_US locale
            (e.g. 12:05 PM)




            Now what format do you want your time to be displayed in?



            for Medium display, use:



            <span [innerHTML]="(txns.startDateTime |  date:'medium')"></span>


            and it's better if you use [innerText] in stead of HTML for span contents.



            to get something like medium date without seconds use 'MMM d, y h:mm a'



            Dateoffset filter:



            transform(value: any, format = 'MM/dd/yyyy'): string {
            let formattedDt: string;
            if (value) {
            if (DateUtil.DATE_TIMEZONE_REGEX.test(value)) {
            value = this.removeTimezone(value);
            }
            formattedDt = this.datePipe.transform(new Date(value), format);
            }
            return formattedDt;
            }

            private removeTimezone(value: any): string {
            const timezoneDashIndex = value.lastIndexOf('-');
            return value.slice(0, timezoneDashIndex);
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 13 '18 at 17:38

























            answered Nov 13 '18 at 16:59









            nircraftnircraft

            1,343419




            1,343419













            • I want to display the date and time in 'Medium' format. can you please help on this

              – vishnu
              Nov 13 '18 at 17:05











            • I tried like this, (txns.startDateTime | date:'medium'), but still it showing time as 12:00:00 AM.

              – vishnu
              Nov 13 '18 at 17:09











            • @vishnu , what is your desired output? medium will show date time like this: Sep 3, 2010 12:05:08 PM, so 12:00:00AM is fine, If you do not want seconds, use 'short'. for getting just time use 'shortTime'

              – nircraft
              Nov 13 '18 at 17:12













            • I am getting the response from server is, '2018-11-13T20:47:47.866'. I want to show like Nov 13, 2018 08:47 PM

              – vishnu
              Nov 13 '18 at 17:15











            • @vishnu, then you should use 'MMM d, y h:mm a' as your filter format. hope it helps. I have updated my answer for you to accept.

              – nircraft
              Nov 13 '18 at 17:17





















            • I want to display the date and time in 'Medium' format. can you please help on this

              – vishnu
              Nov 13 '18 at 17:05











            • I tried like this, (txns.startDateTime | date:'medium'), but still it showing time as 12:00:00 AM.

              – vishnu
              Nov 13 '18 at 17:09











            • @vishnu , what is your desired output? medium will show date time like this: Sep 3, 2010 12:05:08 PM, so 12:00:00AM is fine, If you do not want seconds, use 'short'. for getting just time use 'shortTime'

              – nircraft
              Nov 13 '18 at 17:12













            • I am getting the response from server is, '2018-11-13T20:47:47.866'. I want to show like Nov 13, 2018 08:47 PM

              – vishnu
              Nov 13 '18 at 17:15











            • @vishnu, then you should use 'MMM d, y h:mm a' as your filter format. hope it helps. I have updated my answer for you to accept.

              – nircraft
              Nov 13 '18 at 17:17



















            I want to display the date and time in 'Medium' format. can you please help on this

            – vishnu
            Nov 13 '18 at 17:05





            I want to display the date and time in 'Medium' format. can you please help on this

            – vishnu
            Nov 13 '18 at 17:05













            I tried like this, (txns.startDateTime | date:'medium'), but still it showing time as 12:00:00 AM.

            – vishnu
            Nov 13 '18 at 17:09





            I tried like this, (txns.startDateTime | date:'medium'), but still it showing time as 12:00:00 AM.

            – vishnu
            Nov 13 '18 at 17:09













            @vishnu , what is your desired output? medium will show date time like this: Sep 3, 2010 12:05:08 PM, so 12:00:00AM is fine, If you do not want seconds, use 'short'. for getting just time use 'shortTime'

            – nircraft
            Nov 13 '18 at 17:12







            @vishnu , what is your desired output? medium will show date time like this: Sep 3, 2010 12:05:08 PM, so 12:00:00AM is fine, If you do not want seconds, use 'short'. for getting just time use 'shortTime'

            – nircraft
            Nov 13 '18 at 17:12















            I am getting the response from server is, '2018-11-13T20:47:47.866'. I want to show like Nov 13, 2018 08:47 PM

            – vishnu
            Nov 13 '18 at 17:15





            I am getting the response from server is, '2018-11-13T20:47:47.866'. I want to show like Nov 13, 2018 08:47 PM

            – vishnu
            Nov 13 '18 at 17:15













            @vishnu, then you should use 'MMM d, y h:mm a' as your filter format. hope it helps. I have updated my answer for you to accept.

            – nircraft
            Nov 13 '18 at 17:17







            @vishnu, then you should use 'MMM d, y h:mm a' as your filter format. hope it helps. I have updated my answer for you to accept.

            – nircraft
            Nov 13 '18 at 17:17















            0














            consider using moment.js library for datatime conversions



            visit momentjs.com



            for your code this is the solution:




            var requiredDateFormat= moment(tsnx.startDateTime).format('MM-DD-YYYY')







            share|improve this answer




























              0














              consider using moment.js library for datatime conversions



              visit momentjs.com



              for your code this is the solution:




              var requiredDateFormat= moment(tsnx.startDateTime).format('MM-DD-YYYY')







              share|improve this answer


























                0












                0








                0







                consider using moment.js library for datatime conversions



                visit momentjs.com



                for your code this is the solution:




                var requiredDateFormat= moment(tsnx.startDateTime).format('MM-DD-YYYY')







                share|improve this answer













                consider using moment.js library for datatime conversions



                visit momentjs.com



                for your code this is the solution:




                var requiredDateFormat= moment(tsnx.startDateTime).format('MM-DD-YYYY')








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 '18 at 20:24









                Abdul HaseebAbdul Haseeb

                12




                12






























                    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%2f53285324%2fformat-date-from-yyyy-mm-ddthhmmss-sss-to-human-readable-format-using-angula%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

                    Florida Star v. B. J. F.

                    Error while running script in elastic search , gateway timeout

                    Adding quotations to stringified JSON object values