Reputation: 51
I am new to android application development , I am developing an app that is going to run in india only, I want to get the time of asia/kolkata timezone without using "joda" library I used the following code but i didn't get expected output
Calendar cal = Calendar.getInstance();
TimeZone tz = cal.getTimeZone();
Log.d("Time zone","="+tz.getDisplayName());
I want the time in hh:mm:ss format
Upvotes: 2
Views: 11363
Reputation: 2124
You do not speak english, so lets talk Java. ;-)
String format = "hh:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setTimeZone(TimeZone.getTimeZone("IST"));
System.out.format("%s\n", sdf.format(new Date()));
IST is India Standard Time or UTC/GMT + 5:30 h. I took this from the android API-Documentation mentioned in a comment of Der Golem (+1) and from the following link: http://www.timeanddate.com/time/zone/india/kolkata
Upvotes: 3
Reputation: 4551
import java.util.Calendar;
import java.util.TimeZone;
public class Main {
public static void main(String[] args) {
Calendar calender = Calendar.getInstance();
calender.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
System.out.println(calender.get(Calendar.HOUR_OF_DAY) + ":" + calender.get(Calendar.MINUTE) + ":" + calender.getActualMinimum(Calendar.SECOND));
}
}
This is a full program that gets the time from the timezone in Asia/Calcutta. It displays hours, minutes and seconds!
Upvotes: 14