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

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

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

DateTime.toDate介绍

[英]Converts this object to a DateMidnight using the same millis and chronology.
[中]使用相同的毫秒和年表将此对象转换为DateMidnight

代码示例

代码示例来源:origin: alibaba/canal

private static Date parseDatetime(String dateStr) {
    Date date = null;
    int len = dateStr.length();
    if (len == 10 && dateStr.charAt(4) == '-' && dateStr.charAt(7) == '-') {
      date = new DateTime(dateStr).toDate();
    } else if (len == 8 && dateStr.charAt(2) == ':' && dateStr.charAt(5) == ':') {
      date = new DateTime("T" + dateStr).toDate();
    } else if (len >= 19 && dateStr.charAt(4) == '-' && dateStr.charAt(7) == '-' && dateStr.charAt(13) == ':'
          && dateStr.charAt(16) == ':') {
      date = new DateTime(dateStr.replace(" ", "T")).toDate();
    }
    return date;
  }
}

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

DateTime dateTime = new DateTime().minusHours(4);
Date date = dateTime.toDate(); // If you ever need this...

代码示例来源:origin: Activiti/Activiti

@Override
 public Date resolveDuedate(String duedate, int maxIterations) {
  try {
   // check if due period was specified
   if(duedate.startsWith("P")){
    return new DateTime(clockReader.getCurrentTime()).plus(Period.parse(duedate)).toDate();
   }

   return DateTime.parse(duedate).toDate();

  } catch (Exception e) {
   throw new ActivitiException("couldn't resolve duedate: " + e.getMessage(), e);
  }
 }
}

代码示例来源:origin: gocd/gocd

public V3X509CertificateGenerator(Date startDate, X500Name issuerDn, X500Name subjectDn,
                 PublicKey publicKey, BigInteger serialNumber) {
  SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfo.getInstance(publicKey.getEncoded());
  this.v3CertGen = new X509v3CertificateBuilder(issuerDn, serialNumber, startDate, new DateTime().plusYears(YEARS).toDate(), subjectDn, publicKeyInfo);
}

代码示例来源:origin: aws/aws-sdk-java

private Date getDefaultExpirationDate() {
  return new DateTime(clock.currentTimeMillis())
      .plusMinutes(SYNTHESIZE_SPEECH_DEFAULT_EXPIRATION_MINUTES)
      .toDate();
}

代码示例来源:origin: azkaban/azkaban

/**
 * @param scheduleTime represents the time when Schedule Servlet receives the Cron Schedule API
 * call.
 * @param timezone is always UTC (after 3.1.0)
 * @return the First Scheduled DateTime to run this flow.
 */
private DateTime getNextCronRuntime(final long scheduleTime, final DateTimeZone timezone,
  final CronExpression ce) {
 Date date = new DateTime(scheduleTime).withZone(timezone).toDate();
 if (ce != null) {
  date = ce.getNextValidTimeAfter(date);
 }
 return new DateTime(date);
}

代码示例来源:origin: aws/aws-sdk-java

private Date getExpirationDate() {
  return new DateTime(clock.currentTimeMillis()).plusMinutes(DEFAULT_EXPIRATION_IN_MINUTES).toDate();
}

代码示例来源:origin: gocd/gocd

private List<Modification> multipleModificationList() {
  List<Modification> modifications = new ArrayList<>();
  Date today = new Date();
  Date yesterday = new DateTime().minusDays(1).toDate();
  Modification modification1 = new Modification("lgao", "Fixing the not checked in files", "foo@bar.com", yesterday, "99");
  modification1.createModifiedFile("build.xml", "\\build", ModifiedAction.added);
  modifications.add(modification1);
  Modification modification2 = new Modification("committer", "Added the README file", "foo@bar.com", today, "100");
  modification2.createModifiedFile("oldbuild.xml", "\\build", ModifiedAction.added);
  modifications.add(modification2);
  Modification modification3 = new Modification("committer <html />", "Added the README file with <html />", "foo@bar.com", today, "101");
  modification3.createModifiedFile("README.txt", "\\build", ModifiedAction.added);
  modifications.add(modification3);
  return modifications;
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

/**
 * Default expiration date construction.
 * Some Payment Gateways may require a different format. Override if necessary or set the property
 * "gateway.config.global.expDateFormat" with a format string to provide the correct format for the configured gateway.
 * @param expMonth
 * @param expYear
 * @return
 */
protected String constructExpirationDate(Integer expMonth, Integer expYear) {
  SimpleDateFormat sdf = new SimpleDateFormat(getGatewayExpirationDateFormat());
  DateTime exp = new DateTime()
      .withYear(expYear)
      .withMonthOfYear(expMonth);
  return sdf.format(exp.toDate());
}

代码示例来源:origin: cloudfoundry/uaa

public Date resolve(String clientId) {
  Integer tokenValiditySeconds = ofNullable(
    clientTokenValidity.getValiditySeconds(clientId)
  ).orElse(
    clientTokenValidity.getZoneValiditySeconds()
  );
  if (tokenValiditySeconds == DEFAULT_TO_GLOBAL_POLICY) {
    tokenValiditySeconds = globalTokenValiditySeconds;
  }
  return new DateTime(timeService.getCurrentTimeMillis()).plusSeconds(tokenValiditySeconds).toDate();
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldBeAbleToParseRFC822Dates() throws Exception {
  Date date = DateUtils.parseRFC822("Tue, 09 Dec 2008 18:56:14 +0800");
  assertThat(date, is(new DateTime("2008-12-09T18:56:14+08:00").toDate()));
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldSerializeDateForCcTray() {
  Date date = new DateTime("2008-12-09T18:56:14+08:00").toDate();
  assertThat(DateUtils.formatIso8601ForCCTray(date), is("2008-12-09T10:56:14Z"));
}

代码示例来源:origin: gocd/gocd

@Test
public void testShouldReturn() {
  DateTime now = new DateTime();
  DateTime yesterday = now.minusDays(1);
  assertEquals(new TimeConverter.ConvertedTime(TimeConverter.getHumanReadableDate(now)),
      timeConverter
          .getConvertedTime(now.toDate(), yesterday.toDate()));
}

代码示例来源:origin: killbill/killbill

@Test(groups = "fast")
public void testLoad() throws CatalogApiException {
  final DefaultVersionedCatalog c = loader.loadDefaultCatalog(Resources.getResource("versionedCatalog").toString());
  Assert.assertEquals(c.getVersions().size(), 4);
  DateTime dt = new DateTime("2011-01-01T00:00:00+00:00");
  Assert.assertEquals(c.getVersions().get(0).getEffectiveDate(), dt.toDate());
  dt = new DateTime("2011-02-02T00:00:00+00:00");
  Assert.assertEquals(c.getVersions().get(1).getEffectiveDate(), dt.toDate());
  dt = new DateTime("2011-02-03T00:00:00+00:00");
  Assert.assertEquals(c.getVersions().get(2).getEffectiveDate(), dt.toDate());
  dt = new DateTime("2011-03-03T00:00:00+00:00");
  Assert.assertEquals(c.getVersions().get(3).getEffectiveDate(), dt.toDate());
}

代码示例来源:origin: gocd/gocd

private X509Certificate createTypeOneX509Certificate(Date startDate, String principalDn, KeyPair keyPair) {
  X509V1CertificateGenerator certGen = new X509V1CertificateGenerator();
  X500Principal principal = new X500Principal(principalDn);
  certGen.setSerialNumber(serialNumber());
  certGen.setIssuerDN(principal);
  certGen.setNotBefore(startDate);
  DateTime now = new DateTime(new Date());
  certGen.setNotAfter(now.plusYears(YEARS).toDate());
  certGen.setSubjectDN(principal);                       // note: same as issuer
  certGen.setPublicKey(keyPair.getPublic());
  certGen.setSignatureAlgorithm(new SystemEnvironment().get(GO_SSL_CERTS_ALGORITHM));
  try {
    return certGen.generate(keyPair.getPrivate(), "BC");
  } catch (Exception e) {
    throw bomb(e);
  }
}

代码示例来源:origin: killbill/killbill

@Test(groups = "fast")
public void testLoadCatalogFromInsideResourceFolder() throws CatalogApiException {
  final DefaultVersionedCatalog c = loader.loadDefaultCatalog("com/acme/SpyCarCustom.xml");
  Assert.assertEquals(c.getVersions().size(), 1);
  final DateTime dt = new DateTime("2015-10-04T00:00:00+00:00");
  Assert.assertEquals(c.getEffectiveDate(), dt.toDate());
  Assert.assertEquals(c.getCatalogName(), "SpyCarCustom");
}

代码示例来源:origin: killbill/killbill

@Test(groups = "fast")
public void testLoadCatalogFromClasspathResourceFolder() throws CatalogApiException {
  final VersionedCatalog c = loader.loadDefaultCatalog("SpyCarBasic.xml");
  Assert.assertEquals(c.getVersions().size(), 1);
  final DateTime dt = new DateTime("2013-02-08T00:00:00+00:00");
  Assert.assertEquals(c.getEffectiveDate(), dt.toDate());
  Assert.assertEquals(c.getCatalogName(), "SpyCarBasic");
}

代码示例来源:origin: gocd/gocd

@Before
public void setUp() {
  nowMod = new Modification("user3", "fixed the build.", null, new DateTime().toDate(), "100");
  nowMod.createModifiedFile("foo.java", ".", ModifiedAction.modified);
  oneHourAgoMod = new Modification("user2", "fixed the build.", null, new DateTime().minusHours(1).toDate(), "89");
  oneHourAgoMod.createModifiedFile("foo.java", ".", ModifiedAction.modified);
  yesterdayMod = new Modification("user1", "fixed the build.", null, new DateTime().minusDays(1).toDate(), "9");
  yesterdayMod.createModifiedFile("foo.java", ".", ModifiedAction.modified);
  material = MaterialsMother.svnMaterial("foo");
  material.setName(new CaseInsensitiveString("Foo"));
}

代码示例来源:origin: gocd/gocd

public static void setBuildingState(JobInstance instance) {
  instance.setAgentUuid("1234");
  DateTime now = new DateTime();
  Date scheduledDate = now.minusMinutes(5).toDate();
  instance.setScheduledDate(scheduledDate);
  setTransitionConditionally(instance, JobState.Scheduled, scheduledDate);
  setTransitionConditionally(instance, JobState.Assigned, now.minusMinutes(4).toDate());
  setTransitionConditionally(instance, JobState.Preparing, now.minusMinutes(3).toDate());
  setTransitionConditionally(instance, JobState.Building, now.minusMinutes(2).toDate());
}

代码示例来源:origin: gocd/gocd

@Test public void shouldBeAbleToParseModifications() throws Exception {
  ConsoleResult result = new ConsoleResult(0, Arrays.asList(("<changeset>\n"
      + "<node>ca3ebb67f527c0ad7ed26b789056823d8b9af23f</node>\n"
      + "<author>cruise</author>\n"
      + "<date>Tue, 09 Dec 2008 18:56:14 +0800</date>\n"
      + "<desc>test</desc>\n"
      + "<files>\n"
      + "<modified>\n"
      + "<file>end2end/file</file>\n"
      + "</modified>\n"
      + "<added>\n"
      + "<file>end2end/file</file>\n"
      + "</added>\n"
      + "<deleted>\n"
      + "</deleted>\n"
      + "</files>\n"
      + "</changeset>").split("\n")), new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
  HgModificationSplitter splitter = new HgModificationSplitter(result);
  List<Modification> list = splitter.modifications();
  assertThat(list.size(), is(1));
  assertThat(list.get(0).getModifiedTime(), is(new DateTime("2008-12-09T18:56:14+08:00").toDate()));
}

相关文章

DateTime类方法