【发布时间】:2014-09-15 14:56:30
【问题描述】:
我正在获取Date 并转换为GMT 格式。我以Thu Jul 24 06:55:56 GMT+05:30 2014 的形式获取它。我希望日期以6/19/2014 12:28:44 PM 的形式显示。谁能一步一步告诉我怎么做。我阅读了以下文档http://developer.android.com/reference/java/text/SimpleDateFormat.html,但即使我使用a 和L,格式也往往保持不变。我在下面发布代码,请指导我。
SimpleDateFormat dateFormatGmt = new SimpleDateFormat("LL/dd/yyyy HH:mm:ss a");
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
SimpleDateFormat dateFormatLocal = new SimpleDateFormat("LL/dd/yyyy HH:mm:ss a");
//Time in GMT
try {
dateFormatLocal.parse( dateFormatGmt.format(new Date()) );
Log.i("gmt time",""+dateFormatLocal.parse( dateFormatGmt.format(new Date()) ));
date_edittext.setText(""+dateFormatLocal.parse( dateFormatGmt.format(new Date()) ));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
【问题讨论】:
标签: android simpledateformat gmt