简体   繁体   中英

Groovy Date code producing unexpected output

Why is below code producing output like this ?

String oldDate = "2013-12-05 01:34:54.270"
Date date = Date.parse( 'yyyy-mm-dd hh:mm:ss', oldDate )
Output : Sat Jan 05 01:34:54 EST 2013

When it should simply produce December 5 as the date in the output ? In fact in the original string whatever month I put in it produces the exact same output.

The problem is your date format isn't correct. mm is for minutes where MM is for month. So it should be:

String oldDate = "2013-12-05 01:34:54.270"
Date date = Date.parse( 'yyyy-MM-dd hh:mm:ss', oldDate )

You can find out more from the Java API docs for SimpleDateFormat .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM