我有Calender对象如下 -
final Calendar calendar = Calendar.getInstance();
我想以下列格式从Calendar对象上面获取/提取日期 -
"Sat Jul 20 14:53:36 GMT+02:00 2013"
任何人都可以告诉我我该怎么做.. !!
答案 0 :(得分:9)
试试这个:
Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd hh:mm:ss 'GMT'Z yyyy");
System.out.println(dateFormat.format(cal.getTime()));
答案 1 :(得分:3)
set()
,add()
和roll()
。getTime()
-method获取Date
- 对象。SimpleDateFormat
按日期格式化日期。答案 2 :(得分:2)
尝试:
final Calendar calendar = Calendar.getInstance();
String dat=new SimpleDateFormat("EEE MMM dd hh:mm:ss 'GMT'Z yyyy").format(calendar.getTime())
System.out.println(dat);//"Sat Jul 20 14:53:36 GMT+02:00 2013"
应该适合你!!
答案 3 :(得分:2)
call getTime() by using Calendar reference
Calendar calendar = Calendar.getInstance();
tv.setText(calendar.getTime() + "");
**or**
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat(
"EEE MMM dd hh:mm:ss 'GMT'Z yyyy");
tv.setText(dateFormat.format(calendar.getTime()));