I
ireallyneedtoknow2007
Hi
I need to get the current time + 15 minutes for a given time zone.
Question: the c.get(...) show warnings such as
"The static field Calendar.HOUR_OF_DAY should be accessed in a static
way"
how do I avoid these warnings? thanks
public String addMinutes(String tz)
{
if (tz.equalsIgnoreCase("E"))tz="US/Eastern";
else if (tz.equalsIgnoreCase("C")) tz="US/Central";
else if (tz.equalsIgnoreCase("M")) tz="US/Mountain";
else if (tz.equalsIgnoreCase("P")) tz="US/Pacific";
else if (tz.equalsIgnoreCase("A")) tz="US/Alaska";
else if (tz.equalsIgnoreCase("H")) tz="US/Hawaii";
DecimalFormat f=new DecimalFormat("00");
Calendar c = Calendar.getInstance(TimeZone.getTimeZone(tz));
c.set
(
Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.YEAR),
Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.MONTH)
+1 ,
Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.DAY_OF_MONTH),
Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.HOUR_OF_DAY),
Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.MINUTE)
);
c.add(Calendar.MINUTE,15 );
// warnings appear below.....
String t=f.format(c.get(c.YEAR)) +
f.format(c.get(c.MONTH)) +
f.format(c.get(c.DAY_OF_MONTH)) +
f.format(c.get(c.HOUR_OF_DAY)) +
f.format(c.MINUTE);
return t;
}
I need to get the current time + 15 minutes for a given time zone.
Question: the c.get(...) show warnings such as
"The static field Calendar.HOUR_OF_DAY should be accessed in a static
way"
how do I avoid these warnings? thanks
public String addMinutes(String tz)
{
if (tz.equalsIgnoreCase("E"))tz="US/Eastern";
else if (tz.equalsIgnoreCase("C")) tz="US/Central";
else if (tz.equalsIgnoreCase("M")) tz="US/Mountain";
else if (tz.equalsIgnoreCase("P")) tz="US/Pacific";
else if (tz.equalsIgnoreCase("A")) tz="US/Alaska";
else if (tz.equalsIgnoreCase("H")) tz="US/Hawaii";
DecimalFormat f=new DecimalFormat("00");
Calendar c = Calendar.getInstance(TimeZone.getTimeZone(tz));
c.set
(
Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.YEAR),
Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.MONTH)
+1 ,
Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.DAY_OF_MONTH),
Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.HOUR_OF_DAY),
Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.MINUTE)
);
c.add(Calendar.MINUTE,15 );
// warnings appear below.....
String t=f.format(c.get(c.YEAR)) +
f.format(c.get(c.MONTH)) +
f.format(c.get(c.DAY_OF_MONTH)) +
f.format(c.get(c.HOUR_OF_DAY)) +
f.format(c.MINUTE);
return t;
}