java.util.Calendar.toInstant()方法的使用及代码示例

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

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

Calendar.toInstant介绍

暂无

代码示例

代码示例来源:origin: oblac/jodd

  1. public static LocalDateTime fromCalendar(final Calendar calendar) {
  2. TimeZone tz = calendar.getTimeZone();
  3. ZoneId zid = tz == null ? ZoneId.systemDefault() : tz.toZoneId();
  4. return LocalDateTime.ofInstant(calendar.toInstant(), zid);
  5. }

代码示例来源:origin: hibernate/hibernate-orm

  1. return ZonedDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() );

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

  1. JSONScanner dateScanner = new JSONScanner(text);
  2. if (dateScanner.scanISO8601DateIfMatch(false)) {
  3. Instant instant = dateScanner.getCalendar().toInstant();
  4. return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

代码示例来源:origin: hibernate/hibernate-orm

  1. return LocalDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() );

代码示例来源:origin: hibernate/hibernate-orm

  1. return ZonedDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() ).toInstant();

代码示例来源:origin: hibernate/hibernate-orm

  1. @Override
  2. public <X> LocalDate wrap(X value, WrapperOptions options) {
  3. if ( value == null ) {
  4. return null;
  5. }
  6. if ( LocalDate.class.isInstance( value ) ) {
  7. return (LocalDate) value;
  8. }
  9. if ( Timestamp.class.isInstance( value ) ) {
  10. final Timestamp ts = (Timestamp) value;
  11. return LocalDateTime.ofInstant( ts.toInstant(), ZoneId.systemDefault() ).toLocalDate();
  12. }
  13. if ( Long.class.isInstance( value ) ) {
  14. final Instant instant = Instant.ofEpochMilli( (Long) value );
  15. return LocalDateTime.ofInstant( instant, ZoneId.systemDefault() ).toLocalDate();
  16. }
  17. if ( Calendar.class.isInstance( value ) ) {
  18. final Calendar calendar = (Calendar) value;
  19. return LocalDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() ).toLocalDate();
  20. }
  21. if ( Date.class.isInstance( value ) ) {
  22. if ( java.sql.Date.class.isInstance( value ) ) {
  23. return ((java.sql.Date) value).toLocalDate();
  24. }
  25. else {
  26. return Instant.ofEpochMilli( ((Date) value).getTime() ).atZone( ZoneId.systemDefault() ).toLocalDate();
  27. }
  28. }
  29. throw unknownWrap( value.getClass() );
  30. }

代码示例来源:origin: hibernate/hibernate-orm

  1. return LocalDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() ).toLocalTime();

代码示例来源:origin: hibernate/hibernate-orm

  1. return OffsetDateTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() );

代码示例来源:origin: hibernate/hibernate-orm

  1. return OffsetTime.ofInstant( calendar.toInstant(), calendar.getTimeZone().toZoneId() );

代码示例来源:origin: com.alibaba/fastjson

  1. JSONScanner dateScanner = new JSONScanner(text);
  2. if (dateScanner.scanISO8601DateIfMatch(false)) {
  3. Instant instant = dateScanner.getCalendar().toInstant();
  4. return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

代码示例来源:origin: stanfordnlp/CoreNLP

  1. builder.setCalendar(doc.get(CalendarAnnotation.class).toInstant().toEpochMilli());
  2. keysToSerialize.remove(CalendarAnnotation.class);

代码示例来源:origin: eclipse/smarthome

  1. /**
  2. * @deprecated The constructor uses Calendar object hence it doesn't store time zone. A new constructor is
  3. * available. Use {@link #DateTimeType(ZonedDateTime)} instead.
  4. *
  5. * @param calendar The Calendar object containing the time stamp.
  6. */
  7. @Deprecated
  8. public DateTimeType(Calendar calendar) {
  9. this.zonedDateTime = ZonedDateTime.ofInstant(calendar.toInstant(), TimeZone.getDefault().toZoneId())
  10. .withFixedOffsetZone();
  11. }

代码示例来源:origin: DV8FromTheWorld/JDA

  1. /**
  2. * Gets the creation-time of a JDA-entity by doing the reverse snowflake algorithm on its id.
  3. * This returns the creation-time of the actual entity on Discords side, not inside JDA.
  4. *
  5. * @param entityId
  6. * The id of the JDA entity where the creation-time should be determined for
  7. *
  8. * @return The creation time of the JDA entity as OffsetDateTime
  9. */
  10. public static OffsetDateTime getCreationTime(long entityId)
  11. {
  12. long timestamp = (entityId >>> TIMESTAMP_OFFSET) + DISCORD_EPOCH;
  13. Calendar gmt = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
  14. gmt.setTimeInMillis(timestamp);
  15. return OffsetDateTime.ofInstant(gmt.toInstant(), gmt.getTimeZone().toZoneId());
  16. }

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

  1. @Converter(autoApply=true)
  2. public class ZonedDateTimeAttributeConverter implements AttributeConverter<ZonedDateTime, Calendar> {
  3. @Override
  4. public Calendar convertToDatabaseColumn(ZonedDateTime entityAttribute) {
  5. if (entityAttribute == null) {
  6. return null;
  7. }
  8. Calendar calendar = Calendar.getInstance();
  9. calendar.setTimeInMillis(entityAttribute.toInstant().toEpochMilli());
  10. calendar.setTimeZone(TimeZone.getTimeZone(entityAttribute.getZone()));
  11. return calendar;
  12. }
  13. @Override
  14. public ZonedDateTime convertToEntityAttribute(Calendar databaseColumn) {
  15. if (databaseColumn == null) {
  16. return null;
  17. }
  18. return ZonedDateTime.ofInstant(databaseColumn.toInstant(), databaseColumn.getTimeZone().toZoneId());
  19. }
  20. }

代码示例来源:origin: openhab/openhab-core

  1. /**
  2. * @deprecated The constructor uses Calendar object hence it doesn't store time zone. A new constructor is
  3. * available. Use {@link #DateTimeType(ZonedDateTime)} instead.
  4. *
  5. * @param calendar The Calendar object containing the time stamp.
  6. */
  7. @Deprecated
  8. public DateTimeType(Calendar calendar) {
  9. this.zonedDateTime = ZonedDateTime.ofInstant(calendar.toInstant(), TimeZone.getDefault().toZoneId())
  10. .withFixedOffsetZone();
  11. }

代码示例来源:origin: theotherp/nzbhydra2

  1. @Override
  2. public Date nextExecutionTime(TriggerContext triggerContext) {
  3. Calendar nextExecutionTime = new GregorianCalendar();
  4. Date lastCompletionTime = runNow ? new Date() : triggerContext.lastCompletionTime();
  5. nextExecutionTime.setTime(lastCompletionTime != null ? lastCompletionTime : new Date());
  6. nextExecutionTime.add(Calendar.MILLISECOND, (int) getIntervalForTask(task));
  7. taskInformations.put(task, new TaskInformation(task.name(), lastCompletionTime != null ? lastCompletionTime.toInstant() : null, nextExecutionTime.toInstant()));
  8. return nextExecutionTime.getTime();
  9. }
  10. });

代码示例来源:origin: com.sqlapp/sqlapp-core

  1. protected ZonedDateTime toZonedDateTime(Calendar cal){
  2. if (cal instanceof GregorianCalendar){
  3. return ((GregorianCalendar)cal).toZonedDateTime();
  4. }
  5. ZoneId zoneId=cal.getTimeZone().toZoneId();
  6. return ZonedDateTime.ofInstant(cal.toInstant(), zoneId);
  7. }

代码示例来源:origin: com.github.PhilippHeuer/events4j

  1. /**
  2. * Register internal listeners
  3. */
  4. private void registerInternalListener() {
  5. // Annotation-based EventListener
  6. onEvent(Event.class).subscribe(event -> {
  7. log.debug("Passed event [{}] to the method based annotation manager at {}.", event.getEventId(), event.getFiredAt().toInstant().toString());
  8. annotationEventManager.dispatch(event);
  9. });
  10. }

代码示例来源:origin: com.vmware.dcp/dcp-common

  1. @Test
  2. public void testParseZonedDateTime() throws Exception {
  3. Calendar cal = Calendar.getInstance();
  4. cal.setTimeZone(TimeZone.getTimeZone("Australia/Sydney"));
  5. cal.set(2013, 4, 30, 23, 38, 27);
  6. cal.set(Calendar.MILLISECOND, 85);
  7. ZoneId zid = ZoneId.of("Australia/Sydney");
  8. ZonedDateTime expected = ZonedDateTime.ofInstant(cal.toInstant(), zid);
  9. ZonedDateTime actual = Utils.fromJson(
  10. "\"2013-05-30T23:38:27.085+10:00[Australia/Sydney]\"", ZonedDateTime.class);
  11. assertEquals(expected, actual);
  12. }

代码示例来源:origin: vmware/xenon

  1. @Test
  2. public void testParseInstant() throws Exception {
  3. Calendar cal = Calendar.getInstance();
  4. cal.setTimeZone(TimeZone.getTimeZone("UTC"));
  5. cal.set(2013, 4, 30, 23, 38, 27);
  6. cal.set(Calendar.MILLISECOND, 85);
  7. Instant expected = cal.toInstant();
  8. Instant actual = Utils.fromJson("\"2013-05-30T23:38:27.085Z\"", Instant.class);
  9. assertEquals(expected, actual);
  10. }

相关文章