Take a look at the following commands:
$ sudo ln -fs /usr/share/zoneinfo/US/Pacific localtime
$ date
Mon Oct 13 15:29:02 PDT 2014
$ sudo ln -fs /usr/share/zoneinfo/US/Hawaii localtime
$ date
Mon Oct 13 12:29:20 HST 2014
That is all well and good. Now I have some software written in java that needs to know how many minutes until midnight so it can perform some maintenance.
Here is the code I came up with:
// Time to perform maintenance
String rawTime = "23:59";
int hours = Integer.parseInt(rawTime.substring(0, 2));
int minutes = Integer.parseInt(rawTime.substring(3, 5));
// Get current Time
Calendar c = Calendar.getInstance();
long now = c.getTimeInMillis();
Date dateNow = new Date(now);
System.out.println(new Date(now));
// Get midnight
c.set(Calendar.HOUR_OF_DAY, hours);
c.set(Calendar.MINUTE, minutes);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
Date midnight = new Date(c.getTimeInMillis());
// Get Difference
System.out.println(String.format("Calc minutes from %s to %s", dateNow, midnight));
long result = ((midnight.getTime()/60000) - (dateNow.getTime()/60000));
System.out.println((int) result);
Output when linux is set to Hawaii time zone:
Calc minutes from Mon Oct 13 15:36:51 PDT 2014 to Mon Oct 13 23:59:00 PDT 2014
Result: 503
As you can see, I'm not getting the correct time... I'm getting PDT instead of HST. I'm not that concerned with why toString() of a date returns PDT since it is time zone independent but I am concerned with how I should calculate this?
Let's just start with '11:59' calculate how many minutes until '11:59' for whatever linux thinks the time is...I am open to a solution where I set the linux time in a different fashion.
Thanks! this should be this hard...