我使用这些代码来获取我的本地时间:
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar currenDdate = Calendar.getInstance(TimeZone.getDefault());
System.out.print("Last update: "+dateFormat.format(currenDdate.getTime()));
或者:
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar currenDdate = Calendar.getInstance(getTimeZone("GMT+3.5"));
System.out.print("Last update: "+dateFormat.format(currenDdate.getTime()));
但他们都不给我本地时间,他们都给我 GMT 有什么问题吗?
注意:我使用 eclipse 和 android 编程,上面的代码在 java 中可以正确工作,但在 android 中却不能!
我使用 TextView 来显示时间,而不是 system.out.print()
TextView date = (TextView) findViewById(R.id.gold_textView1);
date.setText("Last update: "+dateFormat.format(currenDdate.getTime()));
请帮我找出问题所在
最佳答案
尝试使用 Date currentDate = new Date()
而不是 Calendar
对象。您的 System.out.print()
调用不会改变。另外,请仔细检查您的系统以确保其默认时区设置正确。
关于java - 本地时间有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17973800/