如何在 Android 中获取 IST 时区 [英] How to get IST time zone in Android
本文介绍了如何在 Android 中获取 IST 时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 android 应用程序开发的新手,我正在开发一个仅在印度运行的应用程序,我想在不使用joda"库的情况下获取亚洲/加尔各答时区的时间我使用了以下代码,但没有得到预期的输出
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());
我想要 hh:mm:ss 格式的时间
I want the time in hh:mm:ss format
推荐答案
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!
这篇关于如何在 Android 中获取 IST 时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文