org.joda.time.DateTime.withTime()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(216)

本文整理了Java中org.joda.time.DateTime.withTime()方法的一些代码示例,展示了DateTime.withTime()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTime.withTime()方法的具体详情如下:
包路径:org.joda.time.DateTime
类名称:DateTime
方法名:withTime

DateTime.withTime介绍

[英]Returns a copy of this datetime with the specified time, retaining the date fields.

If the time is already the time passed in, then this is returned.

To set a single field use the properties, for example:

DateTime set = dt.hourOfDay().setCopy(6);

This instance is immutable and unaffected by this method call.
[中]返回具有指定时间的此datetime的副本,保留日期字段。
如果时间已经是传入的时间,则返回this
要设置单个字段,请使用属性,例如:

DateTime set = dt.hourOfDay().setCopy(6);

此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: joda-time/joda-time

/**
 * Returns a copy of this datetime with the specified time, retaining the date fields.
 * <p>
 * If the new time is invalid due to the time-zone, the time will be adjusted.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param time  the local time
 * @return a copy of this datetime with a different time
 * @throws IllegalArgumentException if the time-of-day is invalid for the date
 * @throws NullPointerException if the time is null
 */
public DateTime withTime(LocalTime time) {
  return withTime(
    time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * Returns a copy of this datetime with the specified time, retaining the date fields.
 * <p>
 * If the new time is invalid due to the time-zone, the time will be adjusted.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param time  the local time
 * @return a copy of this datetime with a different time
 * @throws IllegalArgumentException if the time-of-day is invalid for the date
 * @throws NullPointerException if the time is null
 */
public DateTime withTime(LocalTime time) {
  return withTime(
    time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
}

代码示例来源:origin: org.motechproject/motech-platform-commons-date

public static DateTime endOfDay(Date dateTime) {
  final int hour = 23;
  final int minute = 59;
  final int second = 59;
  final int millis = 999;
  return new DateTime(dateTime).withTime(hour, minute, second, millis);
}

代码示例来源:origin: com.github.fosin/cdp-utils

/**
 * 2014-03-02 23:00:23  ===   2014-03-02 00:00:00
 *
 * @param ts ts
 * @return 结果
 */
public static <T extends Date> T firstOfDay(T ts) {
  checkNotNull(ts);
  T cloned = (T) ts.clone();
  cloned.setTime(new DateTime(ts.getTime()).withTime(0, 0, 0, 0).getMillis());
  return cloned;
}

代码示例来源: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: stackoverflow.com

DateTime nowAuckland = 
  DateTime.now(DateTimeZone.forID("Pacific/Auckland"));
boolean addDay = nowAuckland.getHourOfDay() >= 7;
DateTime aucklandAt700 = nowAuckland.withTime(7, 0, 0, 0);
if (addDay) {
  aucklandAt700 = aucklandAt700.plusDays(1);
}

代码示例来源:origin: TUM-Dev/Campus-Android

@Override
  public String interpretTime(int hour) {
    DateTimeFormatter hourFormat = DateTimeFormat.forPattern("HH:mm")
                           .withLocale(Locale.getDefault());
    DateTime time = new DateTime().withTime(hour, 0, 0, 0);
    return hourFormat.print(time);
  }
});

代码示例来源:origin: ywwynm/EverythingDone

public static void createDailyUpdateHabitAlarm(Context context) {
  Intent intent = new Intent(context, DailyUpdateHabitReceiver.class);
  PendingIntent pendingIntent = PendingIntent.getBroadcast(
      context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  DateTime dt = new DateTime().plusDays(1).withTime(0, 0, 0, 0);
  AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
  alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, dt.getMillis(), 86400000, pendingIntent);
}

代码示例来源:origin: com.github.fosin/cdp-utils

/**
 * 2014-03-02 23:00:23  ===   2014-03-31 23:59:59
 *
 * @param ts ts
 * @return 结果
 */
public static <T extends Date> T lastOfMonth(T ts) {
  checkNotNull(ts);
  T cloned = (T) ts.clone();
  cloned.setTime(new DateTime(ts.getTime()).withTime(0, 0, 0, 0).withDayOfMonth(1).plusMonths(1).minusSeconds(1).getMillis());
  return cloned;
}

代码示例来源: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: stackoverflow.com

DateTimeZone zone = DateTimeZone.forID( "America/Montreal" );
DateTime now = DateTime.now( zone );
DateTime bedtime = now.withTime( 22, 0, 0, 0 );  // Today’s bedtime. May be past, future, or this very moment now.
DateTime risetime = bedtime.plusHours( 7 ); // 05:00 next morning.
Interval sleepInterval = new Interval( bedtime, risetime ); 
boolean asleep = sleepInterval.contains( now );  // Half-Open "[)" comparison, beginning is inclusive, ending exclusive.

代码示例来源:origin: GeoODK/collect

@Override
public IAnswerData getAnswer() {
  clearFocus();
  // use picker time, convert to today's date, store as utc
  DateTime ldt =
    (new DateTime()).withTime(mTimePicker.getCurrentHour(), mTimePicker.getCurrentMinute(),
      0, 0);
  //DateTime utc = ldt.withZone(DateTimeZone.forID("UTC"));
  System.out.println("storing:" + ldt);
  return new TimeData(ldt.toDate());
}

代码示例来源:origin: com.yahoo.sql4d/Sql4DCompiler

public Interval getInterval(int daysOffset, int startHourOffset, int endHourOffset) {
  DateTime baseDateTime = getStartTime().withTime(0, 0, 0, 0).plusDays(daysOffset);
  return new Interval(baseDateTime.plusHours(startHourOffset).toString(), 
      baseDateTime.plusHours(endHourOffset).minusSeconds(1).toString());
}

代码示例来源:origin: srikalyc/Sql4D

public Interval getInterval(int daysOffset, int startHourOffset, int endHourOffset) {
  DateTime baseDateTime = getStartTime().withTime(0, 0, 0, 0).plusDays(daysOffset);
  return new Interval(baseDateTime.plusHours(startHourOffset).toString(), 
      baseDateTime.plusHours(endHourOffset).minusSeconds(1).toString());
}

代码示例来源:origin: FenixEdu/fenixedu-academic

@Deprecated
public static Interval getInterval(YearMonthDay startDate, YearMonthDay endDate) {
  long start = startDate == null ? Long.MIN_VALUE : startDate.toDateMidnight().getMillis();
  long end = endDate == null ? Long.MAX_VALUE : endDate.toDateMidnight().toDateTime().withTime(23, 59, 59, 999).getMillis();
  return new Interval(start, end);
}

代码示例来源:origin: FenixEdu/fenixedu-academic

public static Interval getInterval(LocalDate startDate, LocalDate endDate) {
  long start = startDate == null ? Long.MIN_VALUE : startDate.toDateMidnight().getMillis();
  long end = endDate == null ? Long.MAX_VALUE : endDate.toDateMidnight().toDateTime().withTime(23, 59, 59, 999).getMillis();
  return new Interval(start, end);
}

代码示例来源: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: 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());
}

相关文章

DateTime类方法