本文整理汇总了Java中org.joda.time.LocalDateTime类的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime类的具体用法?Java LocalDateTime怎么用?Java LocalDateTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocalDateTime类属于org.joda.time包,在下文中一共展示了LocalDateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runTestWithDefaultFormatterConstant
import org.joda.time.LocalDateTime; //导入依赖的package包/类
@Test
public final void runTestWithDefaultFormatterConstant() throws Exception {
populateDefaultFormatter();
final String sql = "select date '2016-01-01' from elasticsearch." + schema + "." + table;
verifyJsonInPlan(sql, new String[] {
"[{\n" +
" \"from\" : 0,\n" +
" \"size\" : 4000,\n" +
" \"query\" : {\n" +
" \"match_all\" : { }\n" +
" },\n" +
" \"_source\" : {\n" +
" \"includes\" : [ ],\n" +
" \"excludes\" : [ ]\n" +
" }\n" +
"}]"});
testBuilder()
.sqlQuery(sql)
.unOrdered()
.baselineColumns("EXPR$0")
.baselineValues(new LocalDateTime(Timestamp.valueOf("2016-01-01 00:00:00.000")))
.baselineValues(new LocalDateTime(Timestamp.valueOf("2016-01-01 00:00:00.000")))
.baselineValues(new LocalDateTime(Timestamp.valueOf("2016-01-01 00:00:00.000")))
.go();
}
示例2: calculateRadiusOfGyrationOverTime
import org.joda.time.LocalDateTime; //导入依赖的package包/类
/**
* Calculates a list of progressing radius of gyration numbers based on time
* unit given. Currently, day is supported.
*
* @param traces
* location traces of an individual
* @param unit
* spatial distance unit
* @param timeUnit
* time unit for radius of gyration calculation. Day is supported.
* @return an array of calculated radius of gyration.
* @throws TimeUnitNotSupportedException
*/
public double[] calculateRadiusOfGyrationOverTime(List<LocationTrace> traces,
SpatialDistanceUnit unit, TimeUnit timeUnit) throws TimeUnitNotSupportedException{
if (timeUnit != TimeUnit.DAYS){
throw new TimeUnitNotSupportedException(
timeUnit + " is not supported. Please pass days as time unit.");
}
LocationTraceHelper traceHelper = new LocationTraceHelper();
List<LocationTrace> selectedTraces;
LocalDateTime firstTraceTime = traces.get(0).getLocalTime().minusMinutes(1);
LocalDateTime lastTraceTime = traces.get(traces.size()-1).getLocalTime();
double[] rogResults;
LocalDateTime curentEndDate;
int numberOfDays = Days.daysBetween(firstTraceTime, lastTraceTime).getDays();
rogResults = new double[numberOfDays-1];
for(int i=1; i < numberOfDays; i++ ){
curentEndDate = firstTraceTime.plusDays(i).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
selectedTraces = traceHelper.selectBetweenDates(traces, firstTraceTime, curentEndDate);
rogResults[i-1] = calculateRadiusOfGyration(selectedTraces);
}
return rogResults;
}
示例3: testThatEpochTimePrinterWorks
import org.joda.time.LocalDateTime; //导入依赖的package包/类
public void testThatEpochTimePrinterWorks() {
StringBuffer buffer = new StringBuffer();
LocalDateTime now = LocalDateTime.now();
Joda.EpochTimePrinter epochTimePrinter = new Joda.EpochTimePrinter(false);
epochTimePrinter.printTo(buffer, now, Locale.ROOT);
assertThat(buffer.length(), is(10));
// only check the last digit, as seconds go from 0-99 in the unix timestamp and don't stop at 60
assertThat(buffer.toString(), endsWith(String.valueOf(now.getSecondOfMinute() % 10)));
buffer = new StringBuffer();
Joda.EpochTimePrinter epochMilliSecondTimePrinter = new Joda.EpochTimePrinter(true);
epochMilliSecondTimePrinter.printTo(buffer, now, Locale.ROOT);
assertThat(buffer.length(), is(13));
assertThat(buffer.toString(), endsWith(String.valueOf(now.getMillisOfSecond())));
}
示例4: getExpiryStatus
import org.joda.time.LocalDateTime; //导入依赖的package包/类
public CertificateExpiryStatus getExpiryStatus(Duration warningPeriod) {
try {
Date notAfter = getNotAfter();
LocalDateTime now = LocalDateTime.now();
Date notBefore = getNotBefore();
if (now.toDate().after(notAfter) || now.toDate().before(notBefore)) {
return CertificateExpiryStatus.CRITICAL;
}
if (now.plus(warningPeriod).toDate().after(notAfter)) {
return CertificateExpiryStatus.WARNING;
}
return CertificateExpiryStatus.OK;
} catch (CertificateException e) {
return CertificateExpiryStatus.CRITICAL;
}
}
示例5: runTestWithDateFormatter
import org.joda.time.LocalDateTime; //导入依赖的package包/类
@Test
public final void runTestWithDateFormatter() throws Exception {
populateDateFormatter();
final String sql = "select field from elasticsearch." + schema + "." + table;
verifyJsonInPlan(sql, new String[] {
"[{\n" +
" \"from\" : 0,\n" +
" \"size\" : 4000,\n" +
" \"query\" : {\n" +
" \"match_all\" : { }\n" +
" },\n" +
" \"_source\" : {\n" +
" \"includes\" : [ \"field\" ],\n" +
" \"excludes\" : [ ]\n" +
" }\n" +
"}]"});
testBuilder()
.sqlQuery(sql)
.unOrdered()
.baselineColumns("field")
.baselineValues(new LocalDateTime(Timestamp.valueOf("2016-12-09 00:00:00.000")))
.baselineValues(new LocalDateTime(Timestamp.valueOf("2017-10-11 00:00:00.000")))
.baselineValues(new LocalDateTime(Timestamp.valueOf("2017-01-01 00:00:00.000")))
.baselineValues(new LocalDateTime(Timestamp.valueOf("2017-01-01 00:00:00.000")))
.go();
}
示例6: testNotesWithTimesWithRepeater
import org.joda.time.LocalDateTime; //导入依赖的package包/类
@Test
public void testNotesWithTimesWithRepeater() {
shelfTestUtils.setupBook("notebook",
"* Note 1\n"+
"SCHEDULED: <2017-03-10 Fri +1w>\n" +
"* Note 2\n"+
"SCHEDULED: <2017-03-20 Mon 16:00>\n" +
"* Note 3\n" +
"* Note 4\n"+
"SCHEDULED: <2017-03-16 Fri +1w>\n");
ReminderService.LastRun lastRun = new ReminderService.LastRun();
Instant now = Instant.parse("2017-03-15T13:00:00"); // Wed
AppPreferences.remindersForScheduledEnabled(context, true);
List<NoteReminder> notes = ReminderService.getNoteReminders(
context, now, lastRun, ReminderService.TIME_FROM_NOW);
assertEquals(2, notes.size());
assertEquals("Note 4", notes.get(0).getPayload().title);
assertEquals("2017-03-16T09:00:00", new LocalDateTime(notes.get(0).getRunTime()).toString("yyyy-MM-dd'T'HH:mm:ss"));
assertEquals("Note 2", notes.get(1).getPayload().title);
assertEquals("2017-03-20T16:00:00", new LocalDateTime(notes.get(1).getRunTime()).toString("yyyy-MM-dd'T'HH:mm:ss"));
}
示例7: generateData
import org.joda.time.LocalDateTime; //导入依赖的package包/类
private String generateData(boolean printHeader, boolean longTimestamp, String Timezone, String dataFormat)
{
LocalDateTime queryTime = LocalDateTime.now();
if(isTest)
queryTime = LocalDateTime.parse("2016-01-01T00:00:00.000");
// Get the time Values for the current time
scala.collection.Iterable<Tuple3<String, LocalDateTime, Object>> data = SimController.getTimeValue(simConfig.timeSeries(), queryTime);
// Convert the Scala Iterable to a Java one
Iterable<Tuple3<String, LocalDateTime, Object>> generatedValues = JavaConverters.asJavaIterableConverter(data).asJava();
String resultString = "";
if (dataFormat.equals("CSV")){
resultString = createCsv(printHeader, longTimestamp, Timezone, generatedValues);
}
else if (dataFormat.equals("JSON")){
resultString = generateJson(longTimestamp, Timezone, generatedValues);
}
return resultString;
}
示例8: generateJson
import org.joda.time.LocalDateTime; //导入依赖的package包/类
private String generateJson(boolean longTimestamp, String Timezone, Iterable<Tuple3<String, LocalDateTime, Object>> generatedValues){
DataValue value = new DataValue();
generatedValues.forEach(tv -> {
String dataValue = ((Some)tv._3()).get().toString();
String ts = tv._2().toString();
if (longTimestamp){
DateTime localTime = tv._2().toDateTime(DateTimeZone.forID(Timezone));
ts = String.valueOf(localTime.getMillis());
}
value.setTimeStamp(ts);
value.addValue(tv._1(),dataValue);
});
String output = "";
try {
output = mapper.writeValueAsString(value);
} catch (JsonProcessingException e) {
getLogger().error("Error generating JSON: " + e.getMessage());
}
return output;
}
示例9: runTestProjectTimestamp
import org.joda.time.LocalDateTime; //导入依赖的package包/类
@Test
public final void runTestProjectTimestamp() throws Exception {
String sqlQuery = "select `datefield` from elasticsearch." + schema + "." + table;
verifyJsonInPlan(sqlQuery, new String[] {
"=[{\n" +
" \"from\" : 0,\n" +
" \"size\" : 4000,\n" +
" \"query\" : {\n" +
" \"match_all\" : { }\n" +
" },\n" +
" \"_source\" : {\n" +
" \"includes\" : [ \"datefield\" ],\n" +
" \"excludes\" : [ ]\n" +
" }\n" +
"}])"});
testBuilder().sqlQuery(sqlQuery).unOrdered().baselineColumns("datefield")
.baselineValues(new LocalDateTime(Timestamp.valueOf("2014-02-10 10:50:42")))
.baselineValues(new LocalDateTime(Timestamp.valueOf("2014-02-11 10:50:42")))
.baselineValues(new LocalDateTime(Timestamp.valueOf("2014-02-12 10:50:42")))
.baselineValues(new LocalDateTime(Timestamp.valueOf("2014-02-11 10:50:42")))
.baselineValues(new LocalDateTime(Timestamp.valueOf("2014-02-10 10:50:42")))
.go();
}
示例10: nextFile
import org.joda.time.LocalDateTime; //导入依赖的package包/类
@Override
public File nextFile() {
StringBuilder sb = new StringBuilder();
String date = formatter.print(LocalDateTime.now());
if (!date.equals(lastRoll)) {
getFileIndex().set(0);
lastRoll = date;
}
sb.append(getPrefix()).append(date).append("-");
sb.append(getFileIndex().incrementAndGet());
if (getExtension().length() > 0) {
sb.append(".").append(getExtension());
}
currentFile = new File(getBaseDirectory(), sb.toString());
return currentFile;
}
示例11: getSimpleValue
import org.joda.time.LocalDateTime; //导入依赖的package包/类
/**
* スキーマのプロパティ定義に応じて適切な型に変換したプロパティ値オブジェクトを返す.<br/>
* ユーザデータの場合はBoolean型のプロパティ値を文字列に変換する.
* @param prop プロパティオブジェクト
* @param edmType スキーマのプロパティ定義
* @return 適切な型に変換したプロパティ値オブジェクト
*/
@Override
@SuppressWarnings("unchecked")
protected Object getSimpleValue(OProperty<?> prop, EdmType edmType) {
if (edmType.equals(EdmSimpleType.DATETIME)) {
OProperty<LocalDateTime> propD = (OProperty<LocalDateTime>) prop;
LocalDateTime ldt = propD.getValue();
if (ldt != null) {
return ldt.toDateTime().getMillis();
}
}
// Boolean型/Double型のプロパティ値を文字列に変換する
if (prop.getValue() != null
&& (edmType.equals(EdmSimpleType.BOOLEAN) || edmType.equals(EdmSimpleType.DOUBLE))) {
return String.valueOf(prop.getValue());
}
return prop.getValue();
}
示例12: convert
import org.joda.time.LocalDateTime; //导入依赖的package包/类
@Override
public Object convert(@SuppressWarnings("rawtypes") Class clazz, Object arg1) {
if (arg1 instanceof LocalDate) {
return JODA_DATE_FORMAT.print((LocalDate) arg1);
} else if (arg1 instanceof LocalDateTime) {
return JODA_DATETIME_FORMAT.print((LocalDateTime) arg1);
} else if (arg1 instanceof Timestamp) {
return String.format(TIMESTAMP_FORMAT_STRING_WITH_NANOS, arg1, ((Timestamp) arg1).getNanos());
} else if (arg1 instanceof Date) {
// we need to create the date format object here, because it is not thread safe.
DateFormat JDK_DATETIME_FORMAT = new SimpleDateFormat(DATE_TIME_FORMAT_STRING);
return JDK_DATETIME_FORMAT.format((Date) arg1);
} else {
return arg1.toString();
}
}
示例13: castToInteger
import org.joda.time.LocalDateTime; //导入依赖的package包/类
public static boolean castToInteger(FieldReader reader, NullableBigIntHolder out) {
Object o = reader.readObject();
if (o instanceof Number) {
out.value = ((Number) o).longValue();
return true;
} else if (o instanceof Boolean) {
out.value = ((Boolean) o).booleanValue() ? 1 : 0;
return true;
} else if (o instanceof LocalDateTime) {
out.value = toMillis((LocalDateTime) o);
return true;
} else if (o instanceof Text) {
try {
String s = Text.decode(((Text) o).getBytes(), 0, ((Text) o).getLength());
return parseLong(s, out);
} catch (CharacterCodingException e) {
// TODO: is this the best way?
logger.warn("Can't decode text", e);
return false;
}
} else if (o instanceof byte[]) {
return false; // TODO
}
return false;
}
示例14: Box
import org.joda.time.LocalDateTime; //导入依赖的package包/类
/**
* Constructor.
* @param cell cell object
* @param entity OEntity object
*/
public Box(final Cell cell, final OEntity entity) {
this.cell = cell;
if (entity == null) {
// Process for the MAIN BOX
this.name = Box.DEFAULT_BOX_NAME;
// Schema URL of MAIN BOX is the URL of its own cell
this.schema = cell.getUrl();
// Internal ID of MAIN BOX will be together with the ID of the cell.
this.id = cell.getId();
return;
}
this.name = (String) entity.getProperty("Name").getValue();
this.schema = (String) entity.getProperty(P_SCHEMA.getName()).getValue();
if (entity instanceof OEntityWrapper) {
OEntityWrapper oew = (OEntityWrapper) entity;
this.id = oew.getUuid();
}
LocalDateTime dateTime = (LocalDateTime) entity.getProperty(Common.P_PUBLISHED.getName()).getValue();
this.published = dateTime.toDateTime().getMillis();
}
示例15: testToTimeStamp
import org.joda.time.LocalDateTime; //导入依赖的package包/类
@Test
@Ignore("decimal")
public void testToTimeStamp() throws Exception {
String query = "select to_timestamp(cast('800120400.12312' as decimal(38, 5))) as DEC38_TS, to_timestamp(200120400) as INT_TS " +
"from cp.`employee.json` where employee_id < 2";
LocalDateTime result1 = new LocalDateTime(800120400123l, UTC);
LocalDateTime result2 = new LocalDateTime(200120400000l, UTC);
testBuilder()
.sqlQuery(query)
.unOrdered()
.baselineColumns("DEC38_TS", "INT_TS")
.baselineValues(result1, result2)
.go();
}