本文整理了Java中com.datastax.driver.core.LocalDate.fromMillisSinceEpoch()
方法的一些代码示例,展示了LocalDate.fromMillisSinceEpoch()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDate.fromMillisSinceEpoch()
方法的具体详情如下:
包路径:com.datastax.driver.core.LocalDate
类名称:LocalDate
方法名:fromMillisSinceEpoch
[英]Builds a new instance from a number of milliseconds since January 1st, 1970 GMT. Note that if the given number does not correspond to a whole number of days, it will be rounded towards 0.
[中]从1970年1月1日GMT以来的毫秒数生成一个新实例。请注意,如果给定的数字与天数不一致,它将四舍五入到0。
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Return a new {@link LocalDate} with the specified (signed) amount of time added to (or
* subtracted from) the given {@link Calendar} field, based on the calendar's rules.
*
* <p>Note that adding any amount to a field smaller than {@link Calendar#DAY_OF_MONTH} will
* remain without effect, as this class does not keep time components.
*
* <p>See {@link Calendar} javadocs for more information.
*
* @param field a {@link Calendar} field to modify.
* @param amount the amount of date or time to be added to the field.
* @return a new {@link LocalDate} with the specified (signed) amount of time added to (or
* subtracted from) the given {@link Calendar} field.
* @throws IllegalArgumentException if the new date is not in the range [-5877641-06-23;
* 5881580-07-11].
*/
public LocalDate add(int field, int amount) {
GregorianCalendar newCalendar = isoCalendar();
newCalendar.setTimeInMillis(millisSinceEpoch);
newCalendar.add(field, amount);
LocalDate newDate = fromMillisSinceEpoch(newCalendar.getTimeInMillis());
newDate.calendar = newCalendar;
return newDate;
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Builds a new instance from a year/month/day specification.
*
* <p>This method is not lenient, i.e. '2014-12-32' will not be treated as '2015-01-01', but
* instead throw an {@code IllegalArgumentException}.
*
* @param year the year in ISO format (see {@link LocalDate this class's Javadoc}).
* @param month the month. It is 1-based (e.g. 1 for January).
* @param dayOfMonth the day of the month.
* @return the new instance.
* @throws IllegalArgumentException if the corresponding date does not exist in the ISO8601
* calendar.
*/
public static LocalDate fromYearMonthDay(int year, int month, int dayOfMonth) {
int calendarYear = (year <= 0) ? -year + 1 : year;
int calendarEra = (year <= 0) ? GregorianCalendar.BC : GregorianCalendar.AD;
GregorianCalendar calendar = isoCalendar();
// We can't allow leniency because that could mess with our year shift above (for example if the
// arguments were 0, 12, 32)
calendar.setLenient(false);
calendar.clear();
calendar.set(calendarYear, month - 1, dayOfMonth, 0, 0, 0);
calendar.set(Calendar.ERA, calendarEra);
LocalDate date = fromMillisSinceEpoch(calendar.getTimeInMillis());
date.calendar = calendar;
return date;
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
public LocalDate parse(String value) {
if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null;
// single quotes are optional for long literals, mandatory for date patterns
// strip enclosing single quotes, if any
if (ParseUtils.isQuoted(value)) value = ParseUtils.unquote(value);
if (ParseUtils.isLongLiteral(value)) {
long unsigned;
try {
unsigned = Long.parseLong(value);
} catch (NumberFormatException e) {
throw new InvalidTypeException(
String.format("Cannot parse date value from \"%s\"", value), e);
}
try {
int days = CodecUtils.fromCqlDateToDaysSinceEpoch(unsigned);
return LocalDate.fromDaysSinceEpoch(days);
} catch (IllegalArgumentException e) {
throw new InvalidTypeException(
String.format("Cannot parse date value from \"%s\"", value), e);
}
}
try {
Date date = ParseUtils.parseDate(value, pattern);
return LocalDate.fromMillisSinceEpoch(date.getTime());
} catch (ParseException e) {
throw new InvalidTypeException(
String.format("Cannot parse date value from \"%s\"", value), e);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "unit")
public void should_build_from_millis_since_epoch() {
assertThat(fromMillisSinceEpoch(0))
.hasMillisSinceEpoch(0)
.hasDaysSinceEpoch(0)
assertThat(fromMillisSinceEpoch(3600))
.hasMillisSinceEpoch(0)
.hasDaysSinceEpoch(0)
.hasYearMonthDay(1970, 1, 1)
.hasToString("1970-01-01");
assertThat(fromMillisSinceEpoch(-3600))
.hasMillisSinceEpoch(0)
.hasDaysSinceEpoch(0)
fromMillisSinceEpoch(TimeUnit.DAYS.toMillis((long) Integer.MIN_VALUE - 1));
Assertions.fail("Expected an IllegalArgumentException");
} catch (IllegalArgumentException e) {
fromMillisSinceEpoch(TimeUnit.DAYS.toMillis((long) Integer.MAX_VALUE + 1));
Assertions.fail("Expected an IllegalArgumentException");
} catch (IllegalArgumentException e) {
代码示例来源:origin: io.zipkin.zipkin2/zipkin-storage-cassandra
static List<LocalDate> getDays(long endTs, @Nullable Long lookback) {
List<LocalDate> result = new ArrayList<>();
for (Date javaDate : DateUtil.getDays(endTs, lookback)) {
result.add(LocalDate.fromMillisSinceEpoch(javaDate.getTime()));
}
return result;
}
}
代码示例来源:origin: org.hibernate.ogm/hibernate-ogm-cassandra
@Override
protected void doBind(Tuple resultset, X value, String[] names, WrapperOptions options) {
Date date = (Date) javaTypeDescriptor.unwrap( value, value.getClass(), options );
LocalDate localDate = LocalDate.fromMillisSinceEpoch( date.getTime() );
resultset.put( names[0], localDate );
}
};
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
/**
* Return a new {@link LocalDate} with the specified (signed) amount
* of time added to (or subtracted from) the given {@link Calendar} field,
* based on the calendar's rules.
* <p/>
* Note that adding any amount to a field smaller than
* {@link Calendar#DAY_OF_MONTH} will remain without effect,
* as this class does not keep time components.
* <p/>
* See {@link Calendar} javadocs for more information.
*
* @param field a {@link Calendar} field to modify.
* @param amount the amount of date or time to be added to the field.
* @return a new {@link LocalDate} with the specified (signed) amount
* of time added to (or subtracted from) the given {@link Calendar} field.
* @throws IllegalArgumentException if the new date is not in the range [-5877641-06-23; 5881580-07-11].
*/
public LocalDate add(int field, int amount) {
GregorianCalendar newCalendar = isoCalendar();
newCalendar.setTimeInMillis(millisSinceEpoch);
newCalendar.add(field, amount);
LocalDate newDate = fromMillisSinceEpoch(newCalendar.getTimeInMillis());
newDate.calendar = newCalendar;
return newDate;
}
代码示例来源:origin: io.prestosql.cassandra/cassandra-driver
/**
* Return a new {@link LocalDate} with the specified (signed) amount
* of time added to (or subtracted from) the given {@link Calendar} field,
* based on the calendar's rules.
* <p/>
* Note that adding any amount to a field smaller than
* {@link Calendar#DAY_OF_MONTH} will remain without effect,
* as this class does not keep time components.
* <p/>
* See {@link Calendar} javadocs for more information.
*
* @param field a {@link Calendar} field to modify.
* @param amount the amount of date or time to be added to the field.
* @return a new {@link LocalDate} with the specified (signed) amount
* of time added to (or subtracted from) the given {@link Calendar} field.
* @throws IllegalArgumentException if the new date is not in the range [-5877641-06-23; 5881580-07-11].
*/
public LocalDate add(int field, int amount) {
GregorianCalendar newCalendar = isoCalendar();
newCalendar.setTimeInMillis(millisSinceEpoch);
newCalendar.add(field, amount);
LocalDate newDate = fromMillisSinceEpoch(newCalendar.getTimeInMillis());
newDate.calendar = newCalendar;
return newDate;
}
代码示例来源:origin: com.yugabyte/cassandra-driver-core
/**
* Return a new {@link LocalDate} with the specified (signed) amount
* of time added to (or subtracted from) the given {@link Calendar} field,
* based on the calendar's rules.
* <p/>
* Note that adding any amount to a field smaller than
* {@link Calendar#DAY_OF_MONTH} will remain without effect,
* as this class does not keep time components.
* <p/>
* See {@link Calendar} javadocs for more information.
*
* @param field a {@link Calendar} field to modify.
* @param amount the amount of date or time to be added to the field.
* @return a new {@link LocalDate} with the specified (signed) amount
* of time added to (or subtracted from) the given {@link Calendar} field.
* @throws IllegalArgumentException if the new date is not in the range [-5877641-06-23; 5881580-07-11].
*/
public LocalDate add(int field, int amount) {
GregorianCalendar newCalendar = isoCalendar();
newCalendar.setTimeInMillis(millisSinceEpoch);
newCalendar.add(field, amount);
LocalDate newDate = fromMillisSinceEpoch(newCalendar.getTimeInMillis());
newDate.calendar = newCalendar;
return newDate;
}
代码示例来源:origin: com.yugabyte/cassandra-driver-core
/**
* Builds a new instance from a year/month/day specification.
* <p/>
* This method is not lenient, i.e. '2014-12-32' will not be treated as '2015-01-01', but
* instead throw an {@code IllegalArgumentException}.
*
* @param year the year in ISO format (see {@link LocalDate this class's Javadoc}).
* @param month the month. It is 1-based (e.g. 1 for January).
* @param dayOfMonth the day of the month.
* @return the new instance.
* @throws IllegalArgumentException if the corresponding date does not exist in the ISO8601
* calendar.
*/
public static LocalDate fromYearMonthDay(int year, int month, int dayOfMonth) {
int calendarYear = (year <= 0) ? -year + 1 : year;
int calendarEra = (year <= 0) ? GregorianCalendar.BC : GregorianCalendar.AD;
GregorianCalendar calendar = isoCalendar();
// We can't allow leniency because that could mess with our year shift above (for example if the arguments were 0, 12, 32)
calendar.setLenient(false);
calendar.clear();
calendar.set(calendarYear, month - 1, dayOfMonth, 0, 0, 0);
calendar.set(Calendar.ERA, calendarEra);
LocalDate date = fromMillisSinceEpoch(calendar.getTimeInMillis());
date.calendar = calendar;
return date;
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
/**
* Builds a new instance from a year/month/day specification.
* <p/>
* This method is not lenient, i.e. '2014-12-32' will not be treated as '2015-01-01', but
* instead throw an {@code IllegalArgumentException}.
*
* @param year the year in ISO format (see {@link LocalDate this class's Javadoc}).
* @param month the month. It is 1-based (e.g. 1 for January).
* @param dayOfMonth the day of the month.
* @return the new instance.
* @throws IllegalArgumentException if the corresponding date does not exist in the ISO8601
* calendar.
*/
public static LocalDate fromYearMonthDay(int year, int month, int dayOfMonth) {
int calendarYear = (year <= 0) ? -year + 1 : year;
int calendarEra = (year <= 0) ? GregorianCalendar.BC : GregorianCalendar.AD;
GregorianCalendar calendar = isoCalendar();
// We can't allow leniency because that could mess with our year shift above (for example if the arguments were 0, 12, 32)
calendar.setLenient(false);
calendar.clear();
calendar.set(calendarYear, month - 1, dayOfMonth, 0, 0, 0);
calendar.set(Calendar.ERA, calendarEra);
LocalDate date = fromMillisSinceEpoch(calendar.getTimeInMillis());
date.calendar = calendar;
return date;
}
代码示例来源:origin: io.prestosql.cassandra/cassandra-driver
/**
* Builds a new instance from a year/month/day specification.
* <p/>
* This method is not lenient, i.e. '2014-12-32' will not be treated as '2015-01-01', but
* instead throw an {@code IllegalArgumentException}.
*
* @param year the year in ISO format (see {@link LocalDate this class's Javadoc}).
* @param month the month. It is 1-based (e.g. 1 for January).
* @param dayOfMonth the day of the month.
* @return the new instance.
* @throws IllegalArgumentException if the corresponding date does not exist in the ISO8601
* calendar.
*/
public static LocalDate fromYearMonthDay(int year, int month, int dayOfMonth) {
int calendarYear = (year <= 0) ? -year + 1 : year;
int calendarEra = (year <= 0) ? GregorianCalendar.BC : GregorianCalendar.AD;
GregorianCalendar calendar = isoCalendar();
// We can't allow leniency because that could mess with our year shift above (for example if the arguments were 0, 12, 32)
calendar.setLenient(false);
calendar.clear();
calendar.set(calendarYear, month - 1, dayOfMonth, 0, 0, 0);
calendar.set(Calendar.ERA, calendarEra);
LocalDate date = fromMillisSinceEpoch(calendar.getTimeInMillis());
date.calendar = calendar;
return date;
}
代码示例来源:origin: zhicwu/cassandra-jdbc-driver
com.datastax.driver.core.LocalDate.fromMillisSinceEpoch(System.currentTimeMillis()),
new Function<Object, com.datastax.driver.core.LocalDate>() {
public com.datastax.driver.core.LocalDate apply(Object input) {
代码示例来源:origin: com.yugabyte/cassandra-driver-core
@Override
public LocalDate parse(String value) {
if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL"))
return null;
// single quotes are optional for long literals, mandatory for date patterns
// strip enclosing single quotes, if any
if (ParseUtils.isQuoted(value))
value = ParseUtils.unquote(value);
if (ParseUtils.isLongLiteral(value)) {
long unsigned;
try {
unsigned = Long.parseLong(value);
} catch (NumberFormatException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
try {
int days = CodecUtils.fromCqlDateToDaysSinceEpoch(unsigned);
return LocalDate.fromDaysSinceEpoch(days);
} catch (IllegalArgumentException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
}
try {
Date date = ParseUtils.parseDate(value, pattern);
return LocalDate.fromMillisSinceEpoch(date.getTime());
} catch (ParseException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
}
代码示例来源:origin: io.prestosql.cassandra/cassandra-driver
@Override
public LocalDate parse(String value) {
if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL"))
return null;
// single quotes are optional for long literals, mandatory for date patterns
// strip enclosing single quotes, if any
if (ParseUtils.isQuoted(value))
value = ParseUtils.unquote(value);
if (ParseUtils.isLongLiteral(value)) {
long unsigned;
try {
unsigned = Long.parseLong(value);
} catch (NumberFormatException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
try {
int days = CodecUtils.fromCqlDateToDaysSinceEpoch(unsigned);
return LocalDate.fromDaysSinceEpoch(days);
} catch (IllegalArgumentException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
}
try {
Date date = ParseUtils.parseDate(value, pattern);
return LocalDate.fromMillisSinceEpoch(date.getTime());
} catch (ParseException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
@Override
public LocalDate parse(String value) {
if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL"))
return null;
// single quotes are optional for long literals, mandatory for date patterns
// strip enclosing single quotes, if any
if (ParseUtils.isQuoted(value))
value = ParseUtils.unquote(value);
if (ParseUtils.isLongLiteral(value)) {
long unsigned;
try {
unsigned = Long.parseLong(value);
} catch (NumberFormatException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
try {
int days = CodecUtils.fromCqlDateToDaysSinceEpoch(unsigned);
return LocalDate.fromDaysSinceEpoch(days);
} catch (IllegalArgumentException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
}
try {
Date date = ParseUtils.parseDate(value, pattern);
return LocalDate.fromMillisSinceEpoch(date.getTime());
} catch (ParseException e) {
throw new InvalidTypeException(String.format("Cannot parse date value from \"%s\"", value), e);
}
}
代码示例来源:origin: apache/apex-malhar
case TIMESTAMP:
final Date date = ((Getter<Object, Date>)getters.get(i)).get(tuple);
boundStmnt.setDate(i, LocalDate.fromMillisSinceEpoch(date.getTime()));
break;
default:
代码示例来源:origin: org.apache.apex/malhar-contrib
case TIMESTAMP:
final Date date = ((Getter<Object, Date>)getters.get(i)).get(tuple);
boundStmnt.setDate(i, LocalDate.fromMillisSinceEpoch(date.getTime()));
break;
default:
代码示例来源:origin: com.datastax.dse/dse-java-driver-core
@Test(groups = "unit")
public void should_build_from_millis_since_epoch() {
assertThat(fromMillisSinceEpoch(0))
.hasMillisSinceEpoch(0)
.hasDaysSinceEpoch(0)
assertThat(fromMillisSinceEpoch(3600))
.hasMillisSinceEpoch(0)
.hasDaysSinceEpoch(0)
.hasYearMonthDay(1970, 1, 1)
.hasToString("1970-01-01");
assertThat(fromMillisSinceEpoch(-3600))
.hasMillisSinceEpoch(0)
.hasDaysSinceEpoch(0)
fromMillisSinceEpoch(TimeUnit.DAYS.toMillis((long) Integer.MIN_VALUE - 1));
Assertions.fail("Expected an IllegalArgumentException");
} catch (IllegalArgumentException e) {
fromMillisSinceEpoch(TimeUnit.DAYS.toMillis((long) Integer.MAX_VALUE + 1));
Assertions.fail("Expected an IllegalArgumentException");
} catch (IllegalArgumentException e) {
代码示例来源:origin: io.zipkin.dependencies/zipkin-dependencies-cassandra3
@Override
public Void apply(Session session) {
PreparedStatement prepared =
session.prepare(QueryBuilder.insertInto(keyspace, "dependency")
.value("day", QueryBuilder.bindMarker("day"))
.value("parent", QueryBuilder.bindMarker("parent"))
.value("child", QueryBuilder.bindMarker("child"))
.value("calls", QueryBuilder.bindMarker("calls"))
.value("errors", QueryBuilder.bindMarker("errors")));
for (DependencyLink link : links.collect()) {
BoundStatement bound = prepared.bind()
.setDate("day", LocalDate.fromMillisSinceEpoch(day))
.setString("parent", link.parent())
.setString("child", link.child())
.setLong("calls", link.callCount());
if (link.errorCount() > 0L) {
bound.setLong("errors", link.errorCount());
}
session.execute(bound);
}
return null;
}
});
内容来源于网络,如有侵权,请联系作者删除!