Java Date Format
Use SimpleDateFormat#parse() to parse a String in a certain pattern into a Date.
1 | String oldstring = "2011-01-18 00:00:00.0"; |
Use SimpleDateFormat#format() to format a Date into a String in a certain pattern.
1 | String newstring = new SimpleDateFormat("yyyy-MM-dd").format(date); |
Update: as per your failed attempt: the patterns are case sensitive. Read the SimpleDateFormatjavadoc what the individual parts stands for. So stands for example M for months and m for minutes. Also, years exist of four digits, not five. Look closer at the code snippets I posted here above.
from Stack Overflow