Groovy - simple date reformatting [duplicate]












0















This question already has an answer here:




  • Java SimpleDateFormat always returning January for Month

    3 answers




I am using the below code to convert "Oct 09, 2018" to "20181009".



import java.text.SimpleDateFormat
import java.util.Date

def olddate = "Oct 09, 2018"
def date = Date.parse( "MMM DD, yyyy", olddate )
def newDate = new SimpleDateFormat("yyyyMMdd").format(date)


The problem is that I get the below output:



20180109


Irrespective of what date I convert the code returns the month as January (01)










share|improve this question















marked as duplicate by doelleri, pushkin, cfrick, Mark Rotteveel java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 at 14:53


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















    0















    This question already has an answer here:




    • Java SimpleDateFormat always returning January for Month

      3 answers




    I am using the below code to convert "Oct 09, 2018" to "20181009".



    import java.text.SimpleDateFormat
    import java.util.Date

    def olddate = "Oct 09, 2018"
    def date = Date.parse( "MMM DD, yyyy", olddate )
    def newDate = new SimpleDateFormat("yyyyMMdd").format(date)


    The problem is that I get the below output:



    20180109


    Irrespective of what date I convert the code returns the month as January (01)










    share|improve this question















    marked as duplicate by doelleri, pushkin, cfrick, Mark Rotteveel java
    Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 16 at 14:53


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















      0












      0








      0








      This question already has an answer here:




      • Java SimpleDateFormat always returning January for Month

        3 answers




      I am using the below code to convert "Oct 09, 2018" to "20181009".



      import java.text.SimpleDateFormat
      import java.util.Date

      def olddate = "Oct 09, 2018"
      def date = Date.parse( "MMM DD, yyyy", olddate )
      def newDate = new SimpleDateFormat("yyyyMMdd").format(date)


      The problem is that I get the below output:



      20180109


      Irrespective of what date I convert the code returns the month as January (01)










      share|improve this question
















      This question already has an answer here:




      • Java SimpleDateFormat always returning January for Month

        3 answers




      I am using the below code to convert "Oct 09, 2018" to "20181009".



      import java.text.SimpleDateFormat
      import java.util.Date

      def olddate = "Oct 09, 2018"
      def date = Date.parse( "MMM DD, yyyy", olddate )
      def newDate = new SimpleDateFormat("yyyyMMdd").format(date)


      The problem is that I get the below output:



      20180109


      Irrespective of what date I convert the code returns the month as January (01)





      This question already has an answer here:




      • Java SimpleDateFormat always returning January for Month

        3 answers








      java groovy






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 at 23:23









      pushkin

      3,939112651




      3,939112651










      asked Nov 15 at 22:49









      ASHAW401

      32




      32




      marked as duplicate by doelleri, pushkin, cfrick, Mark Rotteveel java
      Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 16 at 14:53


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by doelleri, pushkin, cfrick, Mark Rotteveel java
      Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 16 at 14:53


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          1














          "MMM DD, yyyy is wrong. Change to MMM dd, yyyy; D means "day of year", while d is "day of month". See e.g. https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html






          share|improve this answer






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            "MMM DD, yyyy is wrong. Change to MMM dd, yyyy; D means "day of year", while d is "day of month". See e.g. https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html






            share|improve this answer




























              1














              "MMM DD, yyyy is wrong. Change to MMM dd, yyyy; D means "day of year", while d is "day of month". See e.g. https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html






              share|improve this answer


























                1












                1








                1






                "MMM DD, yyyy is wrong. Change to MMM dd, yyyy; D means "day of year", while d is "day of month". See e.g. https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html






                share|improve this answer














                "MMM DD, yyyy is wrong. Change to MMM dd, yyyy; D means "day of year", while d is "day of month". See e.g. https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 16 at 12:09









                cfrick

                18.1k13452




                18.1k13452










                answered Nov 16 at 7:44









                Evgeny Smirnov

                1,9681516




                1,9681516















                    Popular posts from this blog

                    How to change which sound is reproduced for terminal bell?

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents