本文整理了Java中org.joda.time.DateTime.withDate()
方法的一些代码示例,展示了DateTime.withDate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTime.withDate()
方法的具体详情如下:
包路径:org.joda.time.DateTime
类名称:DateTime
方法名:withDate
[英]Returns a copy of this datetime with the specified date, retaining the time fields.
If the date is already the date passed in, then this
is returned.
To set a single field use the properties, for example:
DateTime set = monthOfYear().setCopy(6);
This instance is immutable and unaffected by this method call.
[中]返回具有指定日期的此datetime的副本,保留时间字段。
如果日期已经是传入的日期,则返回this
。
要设置单个字段,请使用属性,例如:
DateTime set = monthOfYear().setCopy(6);
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: apache/incubator-gobblin
startTime = startTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(), currentTime.getDayOfMonth());
endTime = endTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(), currentTime.getDayOfMonth());
代码示例来源:origin: joda-time/joda-time
/**
* Returns a copy of this datetime with the specified date, retaining the time fields.
* <p>
* If the time is invalid on the new date due to the time-zone, the time will be adjusted.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param date the local date
* @return a copy of this datetime with a different date
* @throws IllegalArgumentException if the time-of-day is invalid for the date
* @throws NullPointerException if the date is null
*/
public DateTime withDate(LocalDate date) {
return withDate(
date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
}
代码示例来源:origin: JodaOrg/joda-time
/**
* Returns a copy of this datetime with the specified date, retaining the time fields.
* <p>
* If the time is invalid on the new date due to the time-zone, the time will be adjusted.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param date the local date
* @return a copy of this datetime with a different date
* @throws IllegalArgumentException if the time-of-day is invalid for the date
* @throws NullPointerException if the date is null
*/
public DateTime withDate(LocalDate date) {
return withDate(
date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
}
代码示例来源:origin: rackerlabs/blueflood
DateTime date = tryParseDateTime(s, stringToParse);
if (date != null) {
resultDateTime = resultDateTime.withDate(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
break;
DateTime date = tryParseDateTime(monthDayOptionalYearFormat, stringToParse);
if (date != null)
resultDateTime = resultDateTime.withDate(resultDateTime.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
代码示例来源:origin: rackerlabs/blueflood
@Test
public void testComplexFormats() {
testFormat("12:24 yesterday", nowDateTime().minusDays(1).withHourOfDay(12).withMinuteOfHour(24));
testFormat("12:24 tomorrow", nowDateTime().plusDays(1).withHourOfDay(12).withMinuteOfHour(24));
testFormat("12:24 today", nowDateTime().withHourOfDay(12).withMinuteOfHour(24));
testFormat("noon 12/30/2014", nowDateTime().withDate(2014, 12, 30).withHourOfDay(12).withMinuteOfHour(0));
int currentYear = referenceDateTime().getYear();
testFormat("15:45 12/30/14", new DateTime(2014, 12, 30, 15, 45, 0, 0));
testFormat("teatime 12/30/2014", new DateTime(2014, 12, 30, 16, 0, 0, 0));
testFormat("midnight Jul 30", new DateTime(currentYear, 07, 30, 0, 0, 0, 0));
testFormat("Jul 30, 2013", new DateTime(2013, 07, 30, 0, 0, 0, 0));
testFormat("Jul 30", new DateTime(currentYear, 07, 30, 0, 0, 0, 0));
testFormat("20141230", new DateTime(2014, 12, 30, 0, 0, 0, 0));
}
代码示例来源:origin: com.thinkbiganalytics.kylo/kylo-operational-metadata-jpa
public JpaBatchJobExecutionStatusCounts(String status, Integer year, Integer month, Integer day, Long count) {
this.status = status;
this.count = count;
this.date = new DateTime().withDate(year, month, day);
}
代码示例来源:origin: stackoverflow.com
DateTime initial = new DateTime( 1970, 1, 1, 22, 30, 0 );
DateTime dayUpdated = initial.withDate( 1980, 2, 3 );
DateTime timeUpdated = initial.withTime( 15, 20, 0, 0 );
// At this point, initial still contains 1970-1-1, 22:30
// dayUpdated is 1980-2-3 22:30
// timeUpdated is 1970-1-1 15:20
代码示例来源:origin: com.thinkbiganalytics.kylo/kylo-operational-metadata-jpa
public JpaBatchJobExecutionStatusCounts(String status, String feedName, Integer year, Integer month, Integer day, Long count) {
this.status = status;
this.count = count;
this.feedName = feedName;
this.date = new DateTime().withDate(year, month, day).withMillisOfDay(0);
}
代码示例来源:origin: org.apache.isis.core/isis-core-applib
/**
* Create a Time object set to the current time.
*/
public Time() {
final DateTime dateTime = Clock.getTimeAsDateTime();
time = dateTime.withDate(1970, 1, 1); // Epoch is 1970-01-01
}
代码示例来源:origin: org.apache.isis/applib
/**
* Create a Time object set to the current time.
*/
public Time() {
final DateTime dateTime = Clock.getTimeAsDateTime();
time = dateTime.withDate(1970, 1, 1); // Epoch is 1970-01-01
}
代码示例来源:origin: metatron-app/metatron-discovery
@JsonIgnore
public DateTime getMaxTime() {
return new DateTime()
.withZone(DateTimeZone.UTC)
.withDate(2037, 12, 31)
.withTime(0, 0, 0, 0);
}
代码示例来源:origin: metatron-app/metatron-discovery
public static DateTime getMaxTime() {
return new DateTime()
.withZone(DateTimeZone.UTC)
.withDate(2037, 12, 31)
.withTime(0, 0, 0, 0);
}
代码示例来源:origin: blurpy/kouchat-android
@Test
public void topicShouldShowCurrentTopicSystemMessageIfNoArgumentsAndTopicSet() throws CommandException {
final long date = new DateTime().withDate(2010, 3, 4).withTime(20, 45, 13, 0).getMillis();
topic.changeTopic(new Topic("What a nice day", "Niles", date));
when(dateTools.dateToString(any(Date.class), anyString())).thenCallRealMethod();
parser.parse("/topic");
verify(messageController).showSystemMessage(
"Topic is: What a nice day (set by Niles at 20:45:13, 04. Mar. 10)");
verify(parser, never()).fixTopic(anyString());
}
代码示例来源:origin: blurpy/kouchat-android
@Test
public void dateToStringShouldConvertSpecifiedDateToStringWithCorrectFormat() {
final Date date = new DateTime().withDate(2014, 5, 13).withTime(23, 52, 28, 0).toDate();
final String dateAsString = dateTools.dateToString(date, "dd.MM.yyyy HH:mm:ss");
assertEquals("13.05.2014 23:52:28", dateAsString);
}
代码示例来源:origin: blurpy/kouchat-android
@Test
public void topicChangedShouldUpdateTopicAndShowTopicIsMessageWhenNotDoneWithLogonYet() {
final Topic topic = new Topic();
when(controller.getTopic()).thenReturn(topic);
when(chatState.isLogonCompleted()).thenReturn(false);
final long time = new DateTime().withDate(2013, 8, 22).withTime(13, 45, 5, 0).toDate().getTime();
responder.topicChanged(300, "See ya!", "Harry", time);
verify(messageController).showSystemMessage("Topic is: See ya! (set by Harry at 13:45:05, 22. Aug. 13)");
verify(userInterface).showTopic();
verifyTopic(topic, "See ya!", "Harry", time);
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-sql
@Test(expected = RuntimeException.class)
public void testForCastTypeNotSupported() {
operands.add(BeamSqlPrimitive.of(SqlTypeName.TIME, DateTime.now()));
Assert.assertEquals(
new DateTime().withDate(2017, 05, 22).withTime(0, 0, 0, 0),
new BeamSqlCastExpression(operands, SqlTypeName.TIMESTAMP)
.evaluate(row, null, BeamSqlExpressionEnvironments.empty())
.getValue());
}
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-sql
@Test
public void testyyMMddDateFormat() {
// test for yy.MM.dd format
operands.add(BeamSqlPrimitive.of(SqlTypeName.VARCHAR, "17.05.21"));
Assert.assertEquals(
new DateTime().withDate(2017, 05, 21).withTimeAtStartOfDay(),
new BeamSqlCastExpression(operands, SqlTypeName.DATE)
.evaluate(row, null, BeamSqlExpressionEnvironments.empty())
.getValue());
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-sql
@Test
public void testDateTimeFormatWithMillis() {
operands.add(BeamSqlPrimitive.of(SqlTypeName.VARCHAR, "2017-05-21 23:59:59.989"));
Assert.assertEquals(
new DateTime().withDate(2017, 05, 22).withTime(0, 0, 0, 0),
new BeamSqlCastExpression(operands, SqlTypeName.TIMESTAMP)
.evaluate(row, null, BeamSqlExpressionEnvironments.empty())
.getValue());
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-sql
@Test
public void testForIntegerToDateCast() {
// test for yyyyMMdd format
operands.add(BeamSqlPrimitive.of(SqlTypeName.INTEGER, 20170521));
Assert.assertEquals(
new DateTime().withDate(2017, 05, 21).withTimeAtStartOfDay(),
new BeamSqlCastExpression(operands, SqlTypeName.DATE)
.evaluate(row, null, BeamSqlExpressionEnvironments.empty())
.getValue());
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-sql
@Test
public void testDateTimeFormat() {
operands.add(BeamSqlPrimitive.of(SqlTypeName.VARCHAR, "2017-05-21 23:59:59"));
Assert.assertEquals(
new DateTime().withDate(2017, 05, 21).withTime(23, 59, 59, 0),
new BeamSqlCastExpression(operands, SqlTypeName.TIMESTAMP)
.evaluate(row, null, BeamSqlExpressionEnvironments.empty())
.getValue());
}
内容来源于网络,如有侵权,请联系作者删除!