I have field in class Test:
private Date date;
Code in main:
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
Date now = new Date();
Test test = new Test();
test.setDate(sdf.parse(now.toString()));
But I have error:
java.text.ParseException: Unparseable date: "Tue Jan 08 14:10:23 GMT 2013"
at java.text.DateFormat.parse(Unknown Source)
How Can I parse today date to sava
now.toString()is not a good way to represent a date as a string, because it uses a ‘default’ format. To represent a date to a string, you can use theformat(Date date)method ofSimpleDateFormat: