I have a problem with this code
public static void main(String[] args) throws IOException, ParseException { String strDate = "2011-01-12 07:50:00"; DateFormat formatter = new SimpleDateFormat("yyyy-mm-dd H:M:S"); Date date = formatter.parse(strDate); System.out.println("Date="+date); }
Exit:Date = Thu Feb 12 07: 01 : 00 EET 2015What am I doing wrong?
Uppercase M is the day of the month pointer. Lowercase m is the minute per hour. Also, you need lowercase s, since upper case S is milliseconds.
However, you need to be closer to this.
yyyy-MM-dd HH:mm:ss
Your format is incorrect, see SimpleDateFormat .
Instead, you want
String strDate = "2011-01-12 07:50:00"; DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
This may be useful to use: Retrieve time from date String
Change "H: mm" to what you want the format to be.
as your question that you check DateFormat formatter = new SimpleDateFormat ("yyyy-mm-dd H: M: S"); in this statement, "yyyy-MM-dd HH: mm: ss" is SimpleDateFormate.