我正在获取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();
}
答案 0 :(得分:0)
使用它:
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.getDefault());
说它是否有效:)
答案 1 :(得分:0)
SimpleDateFormat format = new SimpleDateFormat("MMM dd,yyyy hh:mm a");
String date = format.format(Date.parse("Your date string"));
String strCurrentDate = "Wed, 18 Apr 2012 07:55:29 +0000";
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss Z");
String currentDate = format.format(strCurrentDate);
format = new SimpleDateFormat("MMM dd,yyyy hh:mm a");
String date = format.format(Date.parse(currentDate));
答案 2 :(得分:0)
我不太明白你的问题,但看看:
Date test = new Date();
test.setHours(10);
SimpleDateFormat sdf = new SimpleDateFormat("M/dd/yyyy HH:mm:ss a");
System.out.println(sdf.format(test));
显示 7/24/2014 10:13:01 AM
如果我将setHours
更改为test.setHours(22)
,则显示 2014年7月24日下午10:13:01
希望这会有所帮助。