I am trying following piece of code using the Java Calendar API
class TimeIssue
{
public void showUTCTime(long millis, final String msg)
{
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
cal.setTimeInMillis(0);
System.out.println(msg + "(UTC):" + cal.getTime());
}
public void showLocalTime(long millis, final String msg)
{
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(0);
System.out.println(msg + "(LOCAL):" + cal.getTime());
}
public static void main(String[] args)
{
long epochSec = 0;
TimeIssue obj = new TimeIssue();
obj.showUTCTime(epochSec, "EPOCH");
obj.showLocalTime(epochSec, "EPOCH");
}
}
When I execute this program, I get the output as ( My Time Zone is GMT+5:30)
EPOCH(UTC):Thu Jan 01 05:30:00 IST 1970
EPOCH(LOCAL):Thu Jan 01 05:30:00 IST 1970
I have 2 concerns here
- Should not the first line of the output be Jan 01 00:00:00 UTC 1970
- Why I am getting IST both the times even when I have set the time zone
Could you please suggest what am I missing here ?
Abhishek