任何人都可以以编程方式给我这个问题的确切解决方案,即当我更改设备时间时,它会占用设备时间,但我希望它应该花费来自互联网的实际时间。 我正在使用这段代码...
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String date = dateFormat.format(new Date(System.currentTimeMillis()));
我也尝试过这个
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
int myfrmt =(c.get(Calendar.YEAR) + c.get(Calendar.MONTH) + c.get(Calendar.DAY_OF_MONTH) + c.get(Calendar.HOUR_OF_DAY)+ c.get(Calendar.MINUTE));
String satyam=Integer.toString(myfrmt);`
但在这两种情况下我都得到了设备时间......不是实时的
最佳答案
你尝试过这个吗:
LocationManager locMan = (LocationManager) activity.getSystemService(activity.LOCATION_SERVICE);
long time = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getTime();
这将通过您的网络提供商提供时间。
关于android - 如果我更改了设备时间,如何以编程方式获取 Android 中的实际时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22759043/