如何使用java从日期获取小时数

Bad*_*der 5 java time date-format simpledateformat

什么是12-hours从这个时间开始只获得格式 数小时的日期格式

 Thu Oct 20 13:12:00 GMT+02:00 2011
Run Code Online (Sandbox Code Playgroud)

编辑:

使用此代码

Date eventDate = tempAppointments.get(i).mStartDate
System.out.println(eventDate.toString());

// date pattern
DateFormat df = new SimpleDateFormat("hh:'00' a");//output : Wed Nov 09 11:00:00 GMT+02:00 2011


// get the start date with new format (pattern) 
String hours = df.format(tempAppointments.get(i).mStartDate.getDay());
System.out.print(hours);//output: 02:00 AM
Run Code Online (Sandbox Code Playgroud)

返回时间为

02:00 AM
Run Code Online (Sandbox Code Playgroud)

但是在给定的时间内.一定是02:00 PM.为什么?

lim*_*imc 5

我不确定为什么date.getDay()要把小时数传递给格式化程序(顺便提一下,过时了)。

尝试这个:-

Date date = new Date();
System.out.println("Date: " + date);

DateFormat df = new SimpleDateFormat("hh:'00' a");
String hour = df.format(date);
System.out.println("Hour: " + hour);
Run Code Online (Sandbox Code Playgroud)

输出:

Date: Sat Nov 19 17:57:05 CST 2011
Hour: 05:00 PM
Run Code Online (Sandbox Code Playgroud)