I have 2 strings: "Sun Jun 23" and "22:45". I want to get the long (millisecond?) representation of the date that is indicated by this 2 strings plus the actual year.
I am trying something like this:
String s1 = "Sun Jun 23";
String s2 = "22:45";
long date = new SimpleDateFormat("EEE MMM dd").parse(s1).getTime()
+ new SimpleDateFormat("HH:mm").parse(s2).getTime();
When I convert back the long date format to String with
private SimpleDateFormat sdf;
sdf = new SimpleDateFormat("yyyy.MM.dd_HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
console.getOut().println(sdf.format(date));
I got "1970.06.23_20:45:00"
This indicates 2 problems:
- This doesn't contain the current year. How can I add it?
- Why did I 'lost' 2 hours (from 22:45 to 20:45)