I have a problem resetting hours in Java. For a given date I want to set the hours to 00:00:00.
This is my code :
/**
* Resets milliseconds, se
You would better to primarily set time zone to the DateFormat component like this:
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
Then you can get "00:00:00" time by passing 0 milliseconds to formatter:
String time = dateFormat.format(0);
or you can create Date object:
Date date = new Date(0); // also pass milliseconds
String time = dateFormat.foramt(date);
or you be able to have more possibilities using Calendar component but you should also set timezone as GMT to calendar instance:
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
calendar.set(Calendar.HOUR_OF_DAY, 5);
calendar.set(Calendar.MINUTE, 37);
calendar.set(Calendar.SECOND, 27);
dateFormat.format(calendar.getTime());