本文整理汇总了Java中java.time.ZonedDateTime.getHour方法的典型用法代码示例。如果您正苦于以下问题:Java ZonedDateTime.getHour方法的具体用法?Java ZonedDateTime.getHour怎么用?Java ZonedDateTime.getHour使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.ZonedDateTime
的用法示例。
在下文中一共展示了ZonedDateTime.getHour方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInfo
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private String getInfo() {
ZonedDateTime localTime = mostRecentMessageTime.atZoneSameInstant(ZoneId.systemDefault());
String time = String.format("%s:%02d", localTime.getHour()%12+1, localTime.getMinute()) + " "
+ ((localTime.getHour()>12) ? "PM" : "AM");
String month = localTime.getMonth().name().substring(0,3).toLowerCase();
// month = WordUtils.capitalize(month);
String day = localTime.getDayOfWeek().name().substring(0,3).toLowerCase();
// day = WordUtils.capitalize(day);
String date = day + ", "
+ month + " "
+ localTime.getDayOfMonth();
return user.getName() + " \u2022 " + date + " at " + time;
}
示例2: testParseUTCDateTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void testParseUTCDateTime() throws Exception {
// ARRANGE
String date = "2016-12-31T12:13:14Z";
// ACT
ZonedDateTime dateTime = FormatUtils.parseUTCTime(date);
int year = dateTime.getYear();
int dayOfMonth = dateTime.getDayOfMonth();
int hour = dateTime.getHour();
// ASSERT
assertThat(year, equalTo(2016));
assertThat(dayOfMonth, equalTo(31));
assertThat(hour, equalTo(12));
}
示例3: testParseNonGMTDateTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test
public void testParseNonGMTDateTime() throws Exception {
// ARRANGE
String date = "2016-12-31T12:13:14-07:00";
// ACT
ZonedDateTime dateTime = FormatUtils.parseUTCTime(date);
int year = dateTime.getYear();
int dayOfMonth = dateTime.getDayOfMonth();
int hour = dateTime.getHour();
// ASSERT
assertThat(year, equalTo(2016));
assertThat(dayOfMonth, equalTo(31));
assertThat(hour, equalTo(19));
}
示例4: getTime
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Override
public long getTime() {
ZonedDateTime time = stopWatch.getTime();
long mSecs = ((time.getDayOfMonth() - 1) * 86400 + time.getHour() * 3600
+ time.getMinute() * 60 + time.getSecond()) * 1000
+ time.getNano() / 1000000;
/*
* int offset=time.getOffset().getTotalSeconds();
* System.out.println(" d:"+(time.getDayOfMonth()-1));
* System.out.println(" h:"+time.getHour());
* System.out.println(" m:"+time.getMinute());
* System.out.println(" s:"+time.getSecond());
* System.out.println(" n:"+time.getNano());
* System.out.println(" o:"+offset); System.out.println("ms:"+mSecs);
*/
return mSecs;
}
示例5: testRangeOfZonedDateTimes
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@Test(dataProvider = "ZonedDateTimeRanges")
public void testRangeOfZonedDateTimes(ZonedDateTime start, ZonedDateTime end, Duration step, boolean parallel) {
final boolean ascend = start.isBefore(end);
final Range<ZonedDateTime> range = Range.of(start, end, step, v -> v.getHour() == 6);
final Array<ZonedDateTime> array = range.toArray(parallel);
final ZonedDateTime first = array.first(v -> true).map(ArrayValue::getValue).get();
final ZonedDateTime last = array.last(v -> true).map(ArrayValue::getValue).get();
Assert.assertEquals(array.typeCode(), ArrayType.ZONED_DATETIME);
Assert.assertTrue(!array.style().isSparse());
Assert.assertEquals(range.start(), start, "The range start");
Assert.assertEquals(range.end(), end, "The range end");
int index = 0;
ZonedDateTime value = first;
while (ascend ? value.isBefore(last) : value.isAfter(last)) {
final ZonedDateTime actual = array.getValue(index);
Assert.assertEquals(actual, value, "Value matches at " + index);
Assert.assertTrue(ascend ? actual.compareTo(start) >= 0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + index);
value = ascend ? value.plus(step) : value.minus(step);
while (value.getHour() == 6) value = ascend ? value.plus(step) : value.minus(step);
index++;
}
}
示例6: encodeAsHex
import java.time.ZonedDateTime; //导入方法依赖的package包/类
public static String encodeAsHex(LocalDateTime dateTime) {
ZonedDateTime zonedDateTime = dateTime.atZone(ZoneOffset.UTC);
byte[] bytes = new byte[5];
bytes[0] = (byte) (zonedDateTime.getYear() - 2000);
bytes[1] = (byte) (zonedDateTime.getMonthValue());
bytes[2] = (byte) (zonedDateTime.getDayOfMonth());
bytes[3] = (byte) (zonedDateTime.getHour());
bytes[4] = (byte) (zonedDateTime.getMinute());
return Hex.encodeHexString(bytes);
}
示例7: DatumtijdLiteral
import java.time.ZonedDateTime; //导入方法依赖的package包/类
/**
* @param waarde een DateTime object
*/
public DatumtijdLiteral(final ZonedDateTime waarde) {
super(waarde);
uur = waarde.getHour();
minuut = waarde.getMinute();
seconde = waarde.getSecond();
}
示例8: isEqual
import java.time.ZonedDateTime; //导入方法依赖的package包/类
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
return zdt.getYear() == ts.getYear() + 1900 &&
zdt.getMonthValue() == ts.getMonth() + 1 &&
zdt.getDayOfMonth() == ts.getDate() &&
zdt.getHour() == ts.getHours() &&
zdt.getMinute() == ts.getMinutes() &&
zdt.getSecond() == ts.getSeconds() &&
zdt.getNano() == ts.getNanos();
}
示例9: createIndex
import java.time.ZonedDateTime; //导入方法依赖的package包/类
@SneakyThrows
public void createIndex(String sipId, int xmlVersion, String arclibXml) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Document xml;
try {
xml = factory.newDocumentBuilder().parse(new ByteArrayInputStream(arclibXml.getBytes()));
} catch (ParserConfigurationException | SAXException | IOException e) {
log.error("Error during parsing of XML document");
throw e;
}
XPath xpath = getXpathWithNamespaceContext();
ArclibXmlDocument solrArclibXmlDocument = new ArclibXmlDocument();
SolrInputDocument doc = new SolrInputDocument();
for (IndexFieldConfig conf : getFieldsConfig()) {
NodeList fields = (NodeList) xpath.evaluate(conf.getXpath(), xml, XPathConstants.NODESET);
for (int i = 0; i < fields.getLength(); i++) {
try {
switch (conf.getFieldType()) {
case DATETIME:
Calendar parsedDate = DatatypeConverter.parseDateTime(fields.item(i).getTextContent());
String parsedDateTimeString = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(parsedDate.toInstant().atZone(ZoneId.systemDefault()));
solrArclibXmlDocument.addField(conf.getFieldName(), parsedDateTimeString);
break;
case DATE:
parsedDate = DatatypeConverter.parseDate(fields.item(i).getTextContent());
String parsedDateString = DateTimeFormatter.ISO_LOCAL_DATE.format(parsedDate.toInstant().atZone(ZoneId.systemDefault()));
solrArclibXmlDocument.addField(conf.getFieldName(), parsedDateString);
break;
case TIME:
ZonedDateTime time = DatatypeConverter.parseTime(fields.item(i).getTextContent()).toInstant().atZone(ZoneId.systemDefault());
long parsedTime = time.getHour() * 60 * 60 * 1000 + time.getMinute() * 60 * 1000 + time.getSecond() * 1000;
solrArclibXmlDocument.addField(conf.getFieldName(), parsedTime);
break;
default:
if (conf.isFullText()) {
solrArclibXmlDocument.addField(conf.getFieldName(), nodeToString(fields.item(i)));
} else {
solrArclibXmlDocument.addField(conf.getFieldName(), fields.item(i).getTextContent());
}
}
} catch (IllegalArgumentException | NullPointerException parsingEx) {
String msg = String.format("Could not parse %s as %s", fields.item(i).getTextContent(), conf.getFieldType());
log.error(msg);
throw new BadArgument(msg);
}
}
}
solrArclibXmlDocument.setId(sipId + "_" + xmlVersion);
solrArclibXmlDocument.setDocument(arclibXml);
try {
arclibXmlRepository.save(solrArclibXmlDocument);
} catch (UncategorizedSolrException ex) {
log.error(ex.getMessage());
throw ex;
}
}
示例10: zonedDateTimeToDateValue
import java.time.ZonedDateTime; //导入方法依赖的package包/类
static DateValue zonedDateTimeToDateValue(ZonedDateTime dt) {
return new DateTimeValueImpl(
dt.getYear(), dt.getMonthValue(), dt.getDayOfMonth(),
dt.getHour(), dt.getMinute(), dt.getSecond());
}