本文整理了Java中org.joda.time.LocalDateTime.toDateTime()
方法的一些代码示例,展示了LocalDateTime.toDateTime()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.toDateTime()
方法的具体详情如下:
包路径:org.joda.time.LocalDateTime
类名称:LocalDateTime
方法名:toDateTime
[英]Converts this object to a DateTime using the default zone.
This method will throw an exception if the datetime that would be created does not exist when the time zone is taken into account.
[中]使用默认区域将此对象转换为日期时间。
如果考虑时区时,将创建的日期时间不存在,则此方法将引发异常。
代码示例来源:origin: joda-time/joda-time
/**
* Converts this object to a DateTime using the default zone.
* <p>
* When the time zone is applied, the local date-time may be affected by daylight saving.
* In a daylight saving gap, when the local time does not exist,
* this method will throw an exception.
* In a daylight saving overlap, when the same local time occurs twice,
* this method returns the first occurrence of the local time.
*
* @return <code>this</code>
* @throws IllegalInstantException if the local time does not exist when the time zone is applied
*/
public DateTime toDateTime() {
return toDateTime((DateTimeZone) null);
}
代码示例来源:origin: JodaOrg/joda-time
/**
* Converts this object to a DateTime using the default zone.
* <p>
* When the time zone is applied, the local date-time may be affected by daylight saving.
* In a daylight saving gap, when the local time does not exist,
* this method will throw an exception.
* In a daylight saving overlap, when the same local time occurs twice,
* this method returns the first occurrence of the local time.
*
* @return <code>this</code>
* @throws IllegalInstantException if the local time does not exist when the time zone is applied
*/
public DateTime toDateTime() {
return toDateTime((DateTimeZone) null);
}
代码示例来源:origin: joda-time/joda-time
/**
* Checks if the given {@link LocalDateTime} is within a gap.
* <p>
* When switching from standard time to Daylight Savings Time there is
* typically a gap where a clock hour is missing. This method identifies
* whether the local datetime refers to such a gap.
*
* @param localDateTime the time to check, not null
* @return true if the given datetime refers to a gap
* @since 1.6
*/
public boolean isLocalDateTimeGap(LocalDateTime localDateTime) {
if (isFixed()) {
return false;
}
try {
localDateTime.toDateTime(this);
return false;
} catch (IllegalInstantException ex) {
return true;
}
}
代码示例来源:origin: JodaOrg/joda-time
/**
* Checks if the given {@link LocalDateTime} is within a gap.
* <p>
* When switching from standard time to Daylight Savings Time there is
* typically a gap where a clock hour is missing. This method identifies
* whether the local datetime refers to such a gap.
*
* @param localDateTime the time to check, not null
* @return true if the given datetime refers to a gap
* @since 1.6
*/
public boolean isLocalDateTimeGap(LocalDateTime localDateTime) {
if (isFixed()) {
return false;
}
try {
localDateTime.toDateTime(this);
return false;
} catch (IllegalInstantException ex) {
return true;
}
}
代码示例来源:origin: stackoverflow.com
DateTime myDateBorken = ldt.toDateTime(dtz);
} catch (IllegalArgumentException iae) {
System.out.println("Sure enough, invalid instant due to time zone offset transition!");
DateTime myDate = ldt.toDateTime(dtz);
System.out.println("No problem: "+myDate);
代码示例来源:origin: azkaban/azkaban
private DateTime parseDateTime(final String scheduleDate, final String scheduleTime) {
// scheduleTime: 12,00,pm,PDT
final String[] parts = scheduleTime.split(",", -1);
int hour = Integer.parseInt(parts[0]);
final int minutes = Integer.parseInt(parts[1]);
final boolean isPm = parts[2].equalsIgnoreCase("pm");
final DateTimeZone timezone =
parts[3].equals("UTC") ? DateTimeZone.UTC : DateTimeZone.getDefault();
// scheduleDate: 02/10/2013
DateTime day = null;
if (scheduleDate == null || scheduleDate.trim().length() == 0) {
day = new LocalDateTime().toDateTime();
} else {
day = DateTimeFormat.forPattern("MM/dd/yyyy")
.withZone(timezone).parseDateTime(scheduleDate);
}
hour %= 12;
if (isPm) {
hour += 12;
}
final DateTime firstSchedTime =
day.withHourOfDay(hour).withMinuteOfHour(minutes).withSecondOfMinute(0);
return firstSchedTime;
}
代码示例来源:origin: apache/hive
private Optional<Timestamp> tryParseWithFormat(String strValue) {
checkState(fmt != null);
if (startingDateValue != null) {
// reset value in case any date fields are missing from the date pattern
MutableDateTime mdt = new MutableDateTime(
startingDateValue, ISOChronology.getInstanceUTC());
// Using parseInto() avoids throwing exception when parsing,
// allowing fallback to default timestamp parsing if custom patterns fail.
int ret = fmt.parseInto(mdt, strValue, 0);
// Only accept parse results if we parsed the entire string
if (ret == strValue.length()) {
return Optional.of(Timestamp.ofEpochMilli(mdt.getMillis()));
}
return Optional.empty();
}
try {
LocalDateTime dt = fmt.parseLocalDateTime(strValue);
return Optional.of(
Timestamp.ofEpochMilli(
dt.toDateTime(ISOChronology.getInstanceUTC().getZone()).getMillis()));
} catch (IllegalArgumentException e) {
return Optional.empty();
}
}
代码示例来源:origin: alibaba/fastjson
out.writeLong(dateTime.toDateTime(DateTimeZone.forTimeZone(JSON.defaultTimeZone)).toInstant().getMillis());
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Converts this object to a DateTime using the default zone.
* <p>
* This method will throw an exception if the datetime that would be
* created does not exist when the time zone is taken into account.
*
* @return <code>this</code>
*/
public DateTime toDateTime() {
return toDateTime((DateTimeZone) null);
}
代码示例来源:origin: com.alibaba/fastjson
out.writeLong(dateTime.toDateTime(DateTimeZone.forTimeZone(JSON.defaultTimeZone)).toInstant().getMillis());
代码示例来源:origin: ebean-orm/ebean
@Override
public long convertToMillis(LocalDateTime value) {
return value.toDateTime().getMillis();
}
代码示例来源:origin: ebean-orm/ebean
@Override
protected String toJsonNanos(LocalDateTime value) {
return String.valueOf(value.toDateTime().getMillis());
}
代码示例来源:origin: ebean-orm/ebean
@Override
public Timestamp convertToTimestamp(LocalDateTime t) {
return new Timestamp(t.toDateTime().getMillis());
}
代码示例来源:origin: ebean-orm/ebean
@Override
public Object toJdbcType(Object value) {
if (value instanceof LocalDateTime) {
return new Timestamp(((LocalDateTime) value).toDateTime().getMillis());
}
return BasicTypeConverter.toTimestamp(value);
}
代码示例来源:origin: stackoverflow.com
LocalDateTime local = new LocalDateTime(2015, 10, 02, 11, 31, 40);
DateTime utc = local.toDateTime(DateTimeZone.UTC);
long secondsSinceEpoch = utc.getMillis() / 1000;
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Checks if the given {@link LocalDateTime} is within a gap.
* <p>
* When switching from standard time to Daylight Savings Time there is
* typically a gap where a clock hour is missing. This method identifies
* whether the local datetime refers to such a gap.
*
* @param localDateTime the time to check, not null
* @return true if the given datetime refers to a gap
* @since 1.6
*/
public boolean isLocalDateTimeGap(LocalDateTime localDateTime) {
if (isFixed()) {
return false;
}
try {
localDateTime.toDateTime(this);
return false;
} catch (IllegalArgumentException ex) {
return true;
}
}
代码示例来源:origin: aaberg/sql2o
public DateTime convert(Object val) throws ConverterException {
if (val == null){
return null;
}
try {
// Joda has it's own pluggable converters infrastructure
// it will throw IllegalArgumentException if can't convert
// look @ org.joda.time.convert.ConverterManager
return new LocalDateTime(val).toDateTime(timeZone);
} catch (IllegalArgumentException ex) {
throw new ConverterException("Error while converting type " + val.getClass().toString() + " to jodatime", ex);
}
}
代码示例来源:origin: com.fasterxml.jackson.datatype/jackson-datatype-joda
@Override
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
switch (_serializationShape(provider)) {
case FORMAT_STRING:
gen.writeString(_format.createFormatter(provider).print(value));
break;
case FORMAT_TIMESTAMP:
{
// copied from `LocalDateTimeDeserializer`...
DateTimeZone tz = _format.isTimezoneExplicit() ? _format.getTimeZone()
: DateTimeZone.forTimeZone(provider.getTimeZone());
gen.writeNumber(value.toDateTime(tz).getMillis());
}
break;
case FORMAT_ARRAY:
// Timestamp here actually means an array of values
gen.writeStartArray();
gen.writeNumber(value.year().get());
gen.writeNumber(value.monthOfYear().get());
gen.writeNumber(value.dayOfMonth().get());
gen.writeNumber(value.hourOfDay().get());
gen.writeNumber(value.minuteOfHour().get());
gen.writeNumber(value.secondOfMinute().get());
gen.writeNumber(value.millisOfSecond().get());
gen.writeEndArray();
}
}
}
代码示例来源:origin: org.jadira.usertype/usertype.core
@Override
protected DateTime fromConvertedColumns(Object[] convertedColumns) {
LocalDateTime datePart = (LocalDateTime) convertedColumns[0];
DateTimeZone zone = (DateTimeZone) convertedColumns[1];
DateTime result;
if (datePart == null) {
result = null;
} else {
result = datePart.toDateTime(zone);
}
return result;
}
代码示例来源:origin: stackoverflow.com
public static Date convertJodaTimezone(LocalDateTime date, String srcTz, String destTz) {
DateTime srcDateTime = date.toDateTime(DateTimeZone.forID(srcTz));
DateTime dstDateTime = srcDateTime.withZone(DateTimeZone.forID(destTz));
return dstDateTime.toLocalDateTime().toDateTime().toDate();
}
内容来源于网络,如有侵权,请联系作者删除!