Reputation: 1905
I am trying to get "TimeZoneOffset" in java and with reference to this, I implemented this:
long unix_time_at_midnight;
DateFormat dateFormat= new SimpleDateFormat("MM/dd/yyyy");
Date d = new Date((unix_time*1000)/1000);
String d1 = dateFormat.format(d);
unix_time_at_midnight = Long.parseLong(d1);
int m=TimeZone.getOffset(unix_time_at_midnight) ;
I get "The method getOffset(int, int, int, int, int, int) in the type TimeZone is not applicable for the arguments (long)". Can anyone guide?
Upvotes: 1
Views: 1988
Reputation: 89209
The method Timezone.getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds);
is an abstract class and one has to reference it from a implemented Timezone
subclass.
You're trying to access a non-static method statically, and the compiler is matching it to the abstract method.
The solution you're seeking of is:
int m=TimeZone.getDefault().getOffset(unix_time_at_midnight) ;
EDIT: Looking on TimeZone
on BlackBerry API, I see there is no getOffset(long date)
method, but getOffset(int era, int year, int month, int day, int dayOfWeek, int millis)
.
A possible solution might be:
Date d = new Date((unix_time*1000)/1000)
TimeZone tz = TimeZone.getDefault();
Calendar c = Calendar.getInstance(tz);
c.setTime(d);
int m = tz.getOffset(1, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.DAY_OF_WEEK), c.get(Calendar.MILLISECOND));
Upvotes: 1