• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps GMT time

Thanks, but I already found what that I need and for people with a similar question, or people that want to know the offset between the phones time and the GMT here is what I did in my app:
Code:
TimeZone GMT = TimeZone.getTimeZone("Europe/London"); //because in London its just GMT without adding or subtracting.
Calendar c = Calendar.getInstance();//for getting the phones GMT
TimeZone UTZ = c.getTimeZone();// UTZ = User Time Zone - for getting the users time zone
String components = UTZ.toString();//convert all the variables of timezone to string.
String[] eachComponent = components.split("=");//spliting the components after every "=" sign.
String[] offset = null; //Init the array;
offset = eachComponent[2].split(",");//if you will print out the array in the 3rd position (or 2nd in the array) there will the offset(in milliseconds) a ',' and the name of the next variable.
long l = Long.parseLong(offset[0]);//getting the offset in milliseconds
int i = (int)(((l / 1000) / 60) / 60);//getting the offset in hours
and thats it. :) hope it help other people like it helped me.
 
Back
Top Bottom