本文整理了Java中java.util.Date.getHours()
方法的一些代码示例,展示了Date.getHours()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Date.getHours()
方法的具体详情如下:
包路径:java.util.Date
类名称:Date
方法名:getHours
[英]Returns the gregorian calendar hour of the day for this Date object.
[中]
代码示例来源:origin: alibaba/jstorm
public static String toTimeStr(Date time) {
int hour = time.getHours();
int min = time.getMinutes();
StringBuilder sb = new StringBuilder();
if (hour < 10) {
sb.append(0).append(hour);
} else {
sb.append(hour);
}
sb.append(":");
if (min < 10) {
sb.append(0).append(min);
} else {
sb.append(min);
}
return sb.toString();
}
代码示例来源:origin: prestodb/presto
/**
* Constructs a TimeOfDay from a <code>java.util.Date</code>
* using exactly the same field values avoiding any time zone effects.
* <p>
* Each field is queried from the Date and assigned to the TimeOfDay.
* This is useful to ensure that the field values are the same in the
* created TimeOfDay no matter what the time zone is. For example, if
* the Calendar states that the time is 04:29, then the created TimeOfDay
* will always have the time 04:29 irrespective of time zone issues.
* <p>
* This factory method always creates a TimeOfDay with ISO chronology.
*
* @param date the Date to extract fields from
* @return the created TimeOfDay
* @throws IllegalArgumentException if the calendar is null
* @throws IllegalArgumentException if the date is invalid for the ISO chronology
* @since 1.2
*/
public static TimeOfDay fromDateFields(Date date) {
if (date == null) {
throw new IllegalArgumentException("The date must not be null");
}
return new TimeOfDay(
date.getHours(),
date.getMinutes(),
date.getSeconds(),
(((int) (date.getTime() % 1000)) + 1000) % 1000
);
}
代码示例来源:origin: com.jtransc/jtransc-rt
@Deprecated
@JTranscMethodBody(target = "js", value = "this._date.setMinutes(p0);")
public void setMinutes(int minutes) {
this.setTimestamp(JTranscTime.make(getFullYear(), getMonth(), getDate(), getHours(), minutes, getSeconds(), getMilliseconds()));
}
代码示例来源:origin: prestodb/presto
date.getHours(),
date.getMinutes(),
date.getSeconds(),
(((int) (date.getTime() % 1000)) + 1000) % 1000
);
代码示例来源:origin: stackoverflow.com
final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
Date date = cal.getTime();
mHour = date.getHours();
mMinute = date.getMinutes();
代码示例来源:origin: joda-time/joda-time
/**
* Constructs a TimeOfDay from a <code>java.util.Date</code>
* using exactly the same field values avoiding any time zone effects.
* <p>
* Each field is queried from the Date and assigned to the TimeOfDay.
* This is useful to ensure that the field values are the same in the
* created TimeOfDay no matter what the time zone is. For example, if
* the Calendar states that the time is 04:29, then the created TimeOfDay
* will always have the time 04:29 irrespective of time zone issues.
* <p>
* This factory method always creates a TimeOfDay with ISO chronology.
*
* @param date the Date to extract fields from
* @return the created TimeOfDay
* @throws IllegalArgumentException if the calendar is null
* @throws IllegalArgumentException if the date is invalid for the ISO chronology
* @since 1.2
*/
public static TimeOfDay fromDateFields(Date date) {
if (date == null) {
throw new IllegalArgumentException("The date must not be null");
}
return new TimeOfDay(
date.getHours(),
date.getMinutes(),
date.getSeconds(),
(((int) (date.getTime() % 1000)) + 1000) % 1000
);
}
代码示例来源:origin: openmrs/openmrs-core
/**
* @throws HL7Exception
* @see HL7Util#parseHL7Time(String)
*/
@Test
@SuppressWarnings("deprecation")
public void parseHL7Time_shouldHandle0615() throws HL7Exception {
// set tz to be a __non DST__ timezone so this junit test works everywhere and always
TimeZone originalTimeZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("EAT"));
Date parsedDate = HL7Util.parseHL7Time("0615");
Assert.assertEquals(6, parsedDate.getHours());
Assert.assertEquals(15, parsedDate.getMinutes());
// reset the timezone
TimeZone.setDefault(originalTimeZone);
}
代码示例来源:origin: joda-time/joda-time
date.getHours(),
date.getMinutes(),
date.getSeconds(),
(((int) (date.getTime() % 1000)) + 1000) % 1000
);
代码示例来源:origin: jobxhub/JobX
public static int ofMinutes(Date date){
int h = date.getHours() * 60;
int m = date.getMinutes();
return h+m;
}
代码示例来源:origin: JodaOrg/joda-time
/**
* Constructs a TimeOfDay from a <code>java.util.Date</code>
* using exactly the same field values avoiding any time zone effects.
* <p>
* Each field is queried from the Date and assigned to the TimeOfDay.
* This is useful to ensure that the field values are the same in the
* created TimeOfDay no matter what the time zone is. For example, if
* the Calendar states that the time is 04:29, then the created TimeOfDay
* will always have the time 04:29 irrespective of time zone issues.
* <p>
* This factory method always creates a TimeOfDay with ISO chronology.
*
* @param date the Date to extract fields from
* @return the created TimeOfDay
* @throws IllegalArgumentException if the calendar is null
* @throws IllegalArgumentException if the date is invalid for the ISO chronology
* @since 1.2
*/
public static TimeOfDay fromDateFields(Date date) {
if (date == null) {
throw new IllegalArgumentException("The date must not be null");
}
return new TimeOfDay(
date.getHours(),
date.getMinutes(),
date.getSeconds(),
(((int) (date.getTime() % 1000)) + 1000) % 1000
);
}
代码示例来源:origin: stackoverflow.com
String time = "13:10";
DateFormat sdf = new SimpleDateFormat("HH:mm"); // or "hh:mm" for 12 hour format
Date date = sdf.parse(time);
date.getHours(); // int
date.getMinutes(); // int
代码示例来源:origin: JodaOrg/joda-time
date.getHours(),
date.getMinutes(),
date.getSeconds(),
(((int) (date.getTime() % 1000)) + 1000) % 1000
);
代码示例来源:origin: stackoverflow.com
final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
Date date = cal.getTime();
mHour = date.getHours();
mMinute = date.getMinutes();
代码示例来源:origin: prestodb/presto
date.getMonth() + 1,
date.getDate(),
date.getHours(),
date.getMinutes(),
date.getSeconds(),
(((int) (date.getTime() % 1000)) + 1000) % 1000
);
代码示例来源:origin: stackoverflow.com
SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd hh:mm");
java.util.Date date = null;
try
{
date = form.parse(string);
}
catch (ParseException e)
{
}
SimpleDateFormat postFormater = new SimpleDateFormat("dd-MM-yyyy");
String newDateStr = "at"+date.getHours()+":"+date.getMinutes()+"on"+postFormater.format(date);
代码示例来源:origin: joda-time/joda-time
date.getMonth() + 1,
date.getDate(),
date.getHours(),
date.getMinutes(),
date.getSeconds(),
(((int) (date.getTime() % 1000)) + 1000) % 1000
);
代码示例来源:origin: stackoverflow.com
String myTime = "14:10";
int minsToAdd = 10;
Date date = new Date();
date.setTime((((Integer.parseInt(myTime.split(":")[0]))*60 + (Integer.parseInt(myTime.split(":")[1])))+ date1.getTimezoneOffset())*60000);
System.out.println(date.getHours() + ":"+date.getMinutes());
date.setTime(date.getTime()+ minsToAdd *60000);
System.out.println(date.getHours() + ":"+date.getMinutes());
代码示例来源:origin: com.alibaba/fastjson
@SuppressWarnings("deprecation")
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
if (object == null) {
serializer.out.writeNull();
return;
}
Date date = (Date) object;
JSONObject json = new JSONObject();
json.put("date", date.getDate());
json.put("day", date.getDay());
json.put("hours", date.getHours());
json.put("minutes", date.getMinutes());
json.put("month", date.getMonth());
json.put("seconds", date.getSeconds());
json.put("time", date.getTime());
json.put("timezoneOffset", date.getTimezoneOffset());
json.put("year", date.getYear());
serializer.write(json);
}
}
代码示例来源:origin: stackoverflow.com
DateFormat dateFormat=new SimpleDateFormat("HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); // <-- Add this.
Date hora=dateFormat.parse("00:00:01");
System.out.println(hora.getHours()+" "+hora.getMinutes());
System.out.println("Date "+hora);
System.out.println("Seconds "+TimeUnit.MILLISECONDS.toSeconds(hora.getTime()));
代码示例来源:origin: h2oai/h2o-3
/**
* Instantiate an AutoML object and start it running. Progress can be tracked via its job().
*
* @param buildSpec
* @return
*/
public static AutoML startAutoML(AutoMLBuildSpec buildSpec) {
Date startTime = new Date(); // this is the one and only startTime for this run
synchronized (AutoML.class) {
// protect against two runs whose startTime is the same second
if (lastStartTime != null) {
while (lastStartTime.getYear() == startTime.getYear() &&
lastStartTime.getMonth() == startTime.getMonth() &&
lastStartTime.getDate() == startTime.getDate() &&
lastStartTime.getHours() == startTime.getHours() &&
lastStartTime.getMinutes() == startTime.getMinutes() &&
lastStartTime.getSeconds() == startTime.getSeconds())
startTime = new Date();
}
lastStartTime = startTime;
}
String keyString = buildSpec.build_control.project_name;
AutoML aml = AutoML.makeAutoML(Key.<AutoML>make(keyString), startTime, buildSpec);
DKV.put(aml);
startAutoML(aml);
return aml;
}
内容来源于网络,如有侵权,请联系作者删除!