本文整理了Java中org.joda.time.DateTime.<init>()
方法的一些代码示例,展示了DateTime.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateTime.<init>()
方法的具体详情如下:
包路径:org.joda.time.DateTime
类名称:DateTime
方法名:<init>
[英]Constructs an instance set to the current system millisecond time using ISOChronology
in the default time zone.
[中]在默认时区中使用ISOChronology
将实例集构造为当前系统毫秒时间。
代码示例来源:origin: prestodb/presto
private DateTime toDateTime(long instantNanos)
{
long millisSinceCreate = NANOSECONDS.toMillis(instantNanos - createNanos);
return new DateTime(createTime.getMillis() + millisSinceCreate);
}
}
代码示例来源:origin: stackoverflow.com
DateTime today = new DateTime();
DateTime yesterday = today.minusDays(1);
Duration duration = new Duration(yesterday, today);
System.out.println(duration.getStandardDays());
System.out.println(duration.getStandardHours());
System.out.println(duration.getStandardMinutes());
代码示例来源: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: azkaban/azkaban
/**
* Test when PST-->PDT happens in 2020. -8:00 -> -7:00 See details why confusion happens during
* this change: https://en.wikipedia.org/wiki/Pacific_Time_Zone
*
* This test demonstrates that 2:30 AM will not happen during the daylight saving day on Cron
* settings under PDT/PST. Since we let the cron triggered both at March 8th, and 9th, it will
* execute at March 9th.
*/
@Test
public void testPSTtoPDTdst2() {
final DateTime now = DateTime.now();
final String cronExpression = "0 30 2 8,9 3 ? 2020";
final BasicTimeChecker timeChecker =
new BasicTimeChecker("BasicTimeChecker_1", now.getMillis(),
DateTimeZone.forID("America/Los_Angeles"), true, true, null, cronExpression);
System.out.println("getNextCheckTime = " + timeChecker.getNextCheckTime());
final Condition cond = getCondition(timeChecker);
final DateTime aTime = new DateTime(2020, 3, 9, 2, 30, 0,
DateTimeZone.forID("America/Los_Angeles"));
assertTrue(cond.getNextCheckTime() == aTime.getMillis());
}
代码示例来源:origin: prestodb/presto
@Test
public void testGreatest()
{
assertFunction(
"greatest(TIMESTAMP '2002-01-02 03:04:05.321 +07:09', TIMESTAMP '2001-01-02 01:04:05.321 +02:09', TIMESTAMP '2000-01-02 01:04:05.321 +02:09')",
TIMESTAMP_WITH_TIME_ZONE,
new SqlTimestampWithTimeZone(new DateTime(2002, 1, 2, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
assertFunction(
"greatest(TIMESTAMP '2001-01-02 03:04:05.321 +07:09', TIMESTAMP '2001-01-02 04:04:05.321 +10:09')",
TIMESTAMP_WITH_TIME_ZONE,
new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
}
代码示例来源:origin: prestodb/presto
@Test
public void testParseDatetime()
{
assertFunction("parse_datetime('1960/01/22 03:04', 'YYYY/MM/DD HH:mm')",
TIMESTAMP_WITH_TIME_ZONE,
toTimestampWithTimeZone(new DateTime(1960, 1, 22, 3, 4, 0, 0, DATE_TIME_ZONE)));
assertFunction("parse_datetime('1960/01/22 03:04 Asia/Oral', 'YYYY/MM/DD HH:mm ZZZZZ')",
TIMESTAMP_WITH_TIME_ZONE,
toTimestampWithTimeZone(new DateTime(1960, 1, 22, 3, 4, 0, 0, DateTimeZone.forID("Asia/Oral"))));
assertFunction("parse_datetime('1960/01/22 03:04 +0500', 'YYYY/MM/DD HH:mm Z')",
TIMESTAMP_WITH_TIME_ZONE,
toTimestampWithTimeZone(new DateTime(1960, 1, 22, 3, 4, 0, 0, DateTimeZone.forOffsetHours(5))));
}
代码示例来源: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: stackoverflow.com
DateTime start = new DateTime(2010, 5, 25, 12, 0, 0, 0);
DateTime end = new DateTime(2010, 5, 25, 21, 0, 0, 0);
Interval interval = new Interval(start, end);
DateTime test = new DateTime(2010, 5, 25, 16, 0, 0, 0);
System.out.println(interval.contains(test));
代码示例来源:origin: azkaban/azkaban
/**
* Test when PST-->PDT happens in 2020. -8:00 -> -7:00 See details why confusion happens during
* this change: https://en.wikipedia.org/wiki/Pacific_Time_Zone
*
* This test demonstrates that if the cron is under UTC settings, When daylight saving change
* occurs, 2:30 will be changed to 3:30 at that day.
*/
@Test
public void testPSTtoPDTunderUTC() {
final DateTime now = DateTime.now();
// 10:30 UTC == 2:30 PST
final String cronExpression = "0 30 10 8 3 ? 2020";
final BasicTimeChecker timeChecker =
new BasicTimeChecker("BasicTimeChecket_1", now.getMillis(),
DateTimeZone.UTC, true, true, null, cronExpression);
System.out.println("getNextCheckTime = " + timeChecker.getNextCheckTime());
final Condition cond = getCondition(timeChecker);
final DateTime spring2020UTC = new DateTime(2020, 3, 8, 10, 30, 0, DateTimeZone.UTC);
final DateTime spring2020PDT = new DateTime(2020, 3, 8, 3, 30, 0,
DateTimeZone.forID("America/Los_Angeles"));
assertTrue(cond.getNextCheckTime() == spring2020UTC.getMillis());
assertTrue(cond.getNextCheckTime() == spring2020PDT.getMillis());
}
代码示例来源:origin: prestodb/presto
@Test
public void testCastToTimestampWithTimeZone()
{
assertFunction("cast(TIME '03:04:05.321 +07:09' as timestamp with time zone)",
TIMESTAMP_WITH_TIME_ZONE,
new SqlTimestampWithTimeZone(new DateTime(1970, 1, 1, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
}
代码示例来源:origin: stackoverflow.com
DateTime dateTime = new DateTime().minusHours(4);
Date date = dateTime.toDate(); // If you ever need this...
代码示例来源:origin: prestodb/presto
public TimestampStreamReader(StreamDescriptor streamDescriptor, DateTimeZone hiveStorageTimeZone, LocalMemoryContext systemMemoryContext)
{
this.streamDescriptor = requireNonNull(streamDescriptor, "stream is null");
this.baseTimestampInSeconds = new DateTime(2015, 1, 1, 0, 0, requireNonNull(hiveStorageTimeZone, "hiveStorageTimeZone is null")).getMillis() / MILLIS_PER_SECOND;
this.systemMemoryContext = requireNonNull(systemMemoryContext, "systemMemoryContext is null");
}
代码示例来源:origin: prestodb/presto
@Test
public void testDatePlusInterval()
{
assertFunction("DATE '2001-1-22' + INTERVAL '3' day", DATE, toDate(new DateTime(2001, 1, 25, 0, 0, 0, 0, UTC)));
assertFunction("INTERVAL '3' day + DATE '2001-1-22'", DATE, toDate(new DateTime(2001, 1, 25, 0, 0, 0, 0, UTC)));
assertFunction("DATE '2001-1-22' + INTERVAL '3' month", DATE, toDate(new DateTime(2001, 4, 22, 0, 0, 0, 0, UTC)));
assertFunction("INTERVAL '3' month + DATE '2001-1-22'", DATE, toDate(new DateTime(2001, 4, 22, 0, 0, 0, 0, UTC)));
assertFunction("DATE '2001-1-22' + INTERVAL '3' year", DATE, toDate(new DateTime(2004, 1, 22, 0, 0, 0, 0, UTC)));
assertFunction("INTERVAL '3' year + DATE '2001-1-22'", DATE, toDate(new DateTime(2004, 1, 22, 0, 0, 0, 0, UTC)));
assertInvalidFunction("DATE '2001-1-22' + INTERVAL '3' hour", "Cannot add hour, minutes or seconds to a date");
assertInvalidFunction("INTERVAL '3' hour + DATE '2001-1-22'", "Cannot add hour, minutes or seconds to a date");
}
代码示例来源: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: stackoverflow.com
final DateTime today = new DateTime().withTime(0, 0, 0, 0);
System.out.println(today);
代码示例来源:origin: azkaban/azkaban
/**
* Test when PDT-->PST happens in 2020. -7:00 -> -8:00 See details why confusion happens during
* this change: https://en.wikipedia.org/wiki/Pacific_Time_Zone
*
* This test cronDayLightPacificWinter2 is in order to be compared against the
* cronDayLightPacificWinter1.
*
* In this Test, we let job run at 0:59 at Nov.1st, 2020. it shows that it is 7:59 UTC The test
* shows 7:59 UTC jump to 9:00 UTC.
*/
@Test
public void testPDTtoPSTdst2() {
final DateTime now = DateTime.now();
// 7:59 UTC == 0:59 PDT (difference is 7 hours)
final String cronExpression = "0 59 0 1,2 11 ? 2020";
final BasicTimeChecker timeChecker =
new BasicTimeChecker("BasicTimeChecket_1", now.getMillis(),
DateTimeZone.forID("America/Los_Angeles"), true, true, null, cronExpression);
System.out.println("getNextCheckTime = " + timeChecker.getNextCheckTime());
final Condition cond = getCondition(timeChecker);
// 7:59 UTC == 0:59 PDT (difference is 7 hours)
final DateTime winter2020 = new DateTime(2020, 11, 1, 7, 59, 0, DateTimeZone.UTC);
final DateTime winter2020_2 = new DateTime(2020, 11, 1, 0, 59, 0,
DateTimeZone.forID("America/Los_Angeles"));
// Local time remains the same.
assertTrue(cond.getNextCheckTime() == winter2020.getMillis());
assertTrue(cond.getNextCheckTime() == winter2020_2.getMillis());
}
代码示例来源:origin: prestodb/presto
@Test
public void testCastToTimestampWithTimeZone()
{
assertFunction("cast(DATE '2001-1-22' as timestamp with time zone)",
TIMESTAMP_WITH_TIME_ZONE,
new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 0, 0, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
}
代码示例来源: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: apache/incubator-druid
@Override
public DateTime increment(DateTime time)
{
return new DateTime(increment(time.getMillis()), getTimeZone());
}
代码示例来源:origin: prestodb/presto
@Test
public void testDateMinusInterval()
{
assertFunction("DATE '2001-1-22' - INTERVAL '3' day", DATE, toDate(new DateTime(2001, 1, 19, 0, 0, 0, 0, UTC)));
assertInvalidFunction("DATE '2001-1-22' - INTERVAL '3' hour", "Cannot subtract hour, minutes or seconds from a date");
}
内容来源于网络,如有侵权,请联系作者删除!