0

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)

pushkin
  • 9,575
  • 15
  • 51
  • 95
ASHAW401
  • 3
  • 2

1 Answers1

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

cfrick
  • 35,203
  • 6
  • 56
  • 68
Evgeny Smirnov
  • 2,886
  • 1
  • 12
  • 22