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

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

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

DateTime.withTimeAtStartOfDay介绍

[英]Returns a copy of this datetime with the time set to the start of the day.

The time will normally be midnight, as that is the earliest time on any given day. However, in some time zones when Daylight Savings Time starts, there is no midnight because time jumps from 11:59 to 01:00. This method handles that situation by returning 01:00 on that date.

This instance is immutable and unaffected by this method call.
[中]返回此datetime的副本,时间设置为一天的开始。
时间通常是午夜,因为这是任何一天最早的时间。然而,在夏令时开始的某些时区中,没有午夜,因为时间从11:59跳到01:00。此方法通过在该日期返回01:00来处理该情况。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: stackoverflow.com

// 5am on the 20th to 1pm on the 21st, October 2013, Brazil
DateTimeZone BRAZIL = DateTimeZone.forID("America/Sao_Paulo");
DateTime start = new DateTime(2013, 10, 20, 5, 0, 0, BRAZIL);
DateTime end = new DateTime(2013, 10, 21, 13, 0, 0, BRAZIL);
System.out.println(daysBetween(start.withTimeAtStartOfDay(),
                end.withTimeAtStartOfDay()).getDays());
// prints 0
System.out.println(daysBetween(start.toLocalDate(),
                end.toLocalDate()).getDays());
// prints 1

代码示例来源:origin: stackoverflow.com

DateTimeZone timeZone = DateTimeZone.forID( "America/Montreal" );
DateTime now = DateTime.now( timeZone );
DateTime todayStart = now.withTimeAtStartOfDay();
DateTime tomorrowStart = now.plusDays( 1 ).withTimeAtStartOfDay();
Interval today = new Interval( todayStart, tomorrowStart );

代码示例来源:origin: Graylog2/graylog2-server

private TreeMap<DateTime, Long> aggregateToDaily(Map<DateTime, Long> histogram) {
  return histogram.entrySet().stream()
      .collect(Collectors.groupingBy(entry -> entry.getKey().withTimeAtStartOfDay(),
          TreeMap::new,
          Collectors.mapping(Map.Entry::getValue, Collectors.summingLong(Long::valueOf))));
}

代码示例来源:origin: stackoverflow.com

DateTime now = new DateTime();
DateTime midnight = now.withTimeAtStartOfDay();
Duration duration = new Duration(midnight, now);
int seconds = duration.toStandardSeconds().getSeconds();

代码示例来源:origin: stackoverflow.com

DateTimeZone timeZone = DateTimeZone.forID( "Europe/Paris" );
// Usually better to specify a time zone rather than rely on default.
DateTime now = new DateTime( timeZone ); // Or, for default time zone: new DateTime()
DateTime monthFromNow = now.plusMonths(1);
DateTime firstOfNextMonth = monthFromNow.dayOfMonth().withMinimumValue();
DateTime firstMomentOfFirstOfNextMonth = firstOfNextMonth.withTimeAtStartOfDay();

代码示例来源:origin: ihaolin/antares

/**
 * 获取指定日期当天的开始时间
 * @param date 日期
 * @return 时间
 */
public static Date startOfDay(Date date) {
  return new DateTime(date).withTimeAtStartOfDay().toDate();
}

代码示例来源:origin: org.isisaddons.module.fakedata/isis-module-fakedata-dom

private static Date asSqlDate(final DateTime dateTime) {
    final DateTime dateTimeAtStartOfDay = dateTime.withTimeAtStartOfDay();
    return new Date(dateTimeAtStartOfDay.toDate().getTime());
  }
}

代码示例来源:origin: stackoverflow.com

import org.joda.time.DateTime;

public static boolean dayIsYesterday(DateTime day) {
  DateTime yesterday = new DateTime().withTimeAtStartOfDay().minusDays(1);
  DateTime inputDay = day.withTimeAtStartOfDay();

  return inputDay.isEqual(yesterday);
}

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

/**
 * Interval should be of form 2014-10-31T00:00:00.000-07:00/2014-11-01T00:00:00.000-07:00
 * @param interval 
 */
public Interval(String interval) {
  String[] dates = interval.split("/");
  Preconditions.checkArgument(dates.length == 2);
  this.startTime = dates[0].replaceAll("'", "");
  this.endTime = dates[1].replaceAll("'", "");
  days = Days.daysBetween(getStartTime().withTimeAtStartOfDay() , getEndTime().withTimeAtStartOfDay() ).getDays() + 1;
}

代码示例来源:origin: plusonelabs/calendar-widget

private void addEmptyDayHeadersBetweenTwoDays(List<WidgetEntry> entries, DateTime fromDayExclusive, DateTime toDayExclusive) {
  DateTime emptyDay = fromDayExclusive.plusDays(1);
  DateTime today = DateUtil.now(getSettings().getTimeZone()).withTimeAtStartOfDay();
  if (emptyDay.isBefore(today)) {
    emptyDay = today;
  }
  while (emptyDay.isBefore(toDayExclusive)) {
    entries.add(new DayHeader(emptyDay));
    emptyDay = emptyDay.plusDays(1);
  }
}

代码示例来源:origin: org.jruby/jruby-complete

/**
 # Create a new Date object representing today.
 #
 # +sg+ specifies the Day of Calendar Reform.
 **/
@JRubyMethod(meta = true)
public static RubyDate today(ThreadContext context, IRubyObject self) { // sg=ITALY
  return new RubyDate(context.runtime, (RubyClass) self, new DateTime(getChronology(context, ITALY, 0)).withTimeAtStartOfDay());
}

代码示例来源:origin: org.jruby/jruby-core

/**
 # Create a new Date object representing today.
 #
 # +sg+ specifies the Day of Calendar Reform.
 **/
@JRubyMethod(meta = true)
public static RubyDate today(ThreadContext context, IRubyObject self) { // sg=ITALY
  return new RubyDate(context.runtime, (RubyClass) self, new DateTime(getChronology(context, ITALY, 0)).withTimeAtStartOfDay());
}

代码示例来源:origin: chengzhx76/weixin-shop-spring-cloud

@Override
public int getCountByDay(String phone) {
  SmsHistory smsHistory = new SmsHistory();
  smsHistory.setPhone(phone);
  DateTime startOfDay = new DateTime().withTimeAtStartOfDay();
  smsHistory.setStartOfDay(new Date(startOfDay.getMillis()));
  return smsHistoryDao.loadOneDayCount(smsHistory);
}
@Override

代码示例来源:origin: chengzhx76/weixin-shop-spring-cloud

@Override
public int getCountByIp(String ip) {
  SmsHistory smsHistory = new SmsHistory();
  smsHistory.setUserIp(ip);
  DateTime startOfDay = new DateTime().withTimeAtStartOfDay();
  smsHistory.setStartOfDay(new Date(startOfDay.getMillis()));
  return smsHistoryDao.loadCurrentIpCount(smsHistory);
}
@Override

代码示例来源:origin: com.yahoo.maha/maha-par-request

public static int getPreviousMonthStartHourId(int currentHourId) {
  return getHours(
    new DateTime((long) currentHourId * 3600 * 1000, TimeUtil.EASTERN).minusMonths(1).withDayOfMonth(1)
      .withTimeAtStartOfDay());
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(meta = true)
public static RubyDate today(ThreadContext context, IRubyObject self, IRubyObject sg) {
  final long start = val2sg(context, sg);
  return new RubyDate(context.runtime, (RubyClass) self, new DateTime(getChronology(context, start, 0)).withTimeAtStartOfDay(), 0, start);
}

代码示例来源:origin: sakaiproject/sakai

static String getLocalAMString(DateTime now) {
  //we need an AM date
  DateTime dt = now.withTimeAtStartOfDay();
  Locale locale= new ResourceLoader("calendar").getLocale();
  DateTimeFormatter df = new DateTimeFormatterBuilder().appendHalfdayOfDayText().toFormatter().withLocale(locale);
  return df.print(dt);
}

代码示例来源:origin: sakaiproject/sakai

static String getLocalPMString(DateTime now) {
  //we need an PM date
  DateTime dt = now.withTimeAtStartOfDay().plusHours(14);
  Locale locale = new ResourceLoader("calendar").getLocale();
  DateTimeFormatter df = new DateTimeFormatterBuilder().appendHalfdayOfDayText().toFormatter().withLocale(locale);
  return df.print(dt);
}

代码示例来源:origin: plusonelabs/calendar-widget

public void testAlldayEventMillis() {
  DateTime today = DateUtil.now(DateTimeZone.UTC).withTimeAtStartOfDay();
  CalendarEvent event = new CalendarEvent(provider.getContext(), provider.getWidgetId(),
      provider.getSettings().getTimeZone(), true);
  event.setEventId(++eventId);
  event.setTitle("Single All day event from millis");
  event.setStartMillis(today.getMillis());
  assertEquals(event.getStartDate().toString(), today.getMillis(), event.getStartMillis());
  assertEquals(event.getEndDate().toString(), today.plusDays(1).getMillis(), event.getEndMillis());
}

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

相关文章

微信公众号

最新文章

更多

DateTime类方法