当前位置: 首页>>代码示例>>Java>>正文


Java LocalDateTime.ofInstant方法代码示例

本文整理汇总了Java中java.time.LocalDateTime.ofInstant方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.ofInstant方法的具体用法?Java LocalDateTime.ofInstant怎么用?Java LocalDateTime.ofInstant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.LocalDateTime的用法示例。


在下文中一共展示了LocalDateTime.ofInstant方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFileDate

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 * Sets as file date its creation, or last access or last modification date.
 *
 * @param fDate A string with value "creationDate", or "lastAccessDate" or "lastModifiedDate".
 */
private LocalDate getFileDate(String fDate) throws ExecutionException {

    LocalDate fileDate = null;
    try {
        Path file = Paths.get(document.getSourceUrl().toURI());
        BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
        if (attr != null && "creationDate".equals(fDate)) {
            LocalDateTime creationTime = LocalDateTime.ofInstant(attr.creationTime().toInstant(), defaultZoneId);
            fileDate = creationTime.toLocalDate();
        } else if (attr != null && "lastAccessDate".equals(fDate)) {
            LocalDateTime lastAccessTime = LocalDateTime.ofInstant(attr.lastAccessTime().toInstant(), defaultZoneId);
            fileDate = lastAccessTime.toLocalDate();
        }
        else if (attr != null && "lastModifiedDate".equals(fDate)) {
            LocalDateTime lastModifiedTime = LocalDateTime.ofInstant(attr.lastModifiedTime().toInstant(), defaultZoneId);
            fileDate = lastModifiedTime.toLocalDate();
        }
    } catch (URISyntaxException | IOException e) {
        e.printStackTrace();
    }
    if (fileDate == null) throw new ExecutionException(referenceDate + " is null for " + document.getName());
    return fileDate;
}
 
开发者ID:pkourdis,项目名称:gateplugin-SUTime,代码行数:29,代码来源:TemporalTagger.java

示例2: testUpdatedDate

import java.time.LocalDateTime; //导入方法依赖的package包/类
public void testUpdatedDate() {
    String baldy = "{viewer={instances={edges=[{node={id=ski_ski_ski, resort=baldy}}]}}}";
    Map<String, Object> variableMap = buildVariableMap("skibob");

    LocalDateTime beforeUpdateDate = LocalDateTime.now();

    // Update skibob
    loadSchemaInstances();

    GraphQLResult result = instanceService.executeQuery(viewSkibobWithUpdateDate, variableMap,
            buildSchemaWriteAccess(), DEFAULT_MAX_RECURSE_DEPTH);
    assertTrue(result.isSuccessful());

    // Extract updateDate from the result
    JsonNode jsonNode = new ObjectMapper().valueToTree(result.toSpecification());
    Long updateDateMillis = jsonNode.at("/data/viewer/instances/edges/0/node/updateDate").asLong();

    assertNotNull(updateDateMillis);

    LocalDateTime updateDate =
            LocalDateTime.ofInstant(Instant.ofEpochMilli(updateDateMillis), ZoneId.systemDefault());

    // The date should be >= beforeUpdateDate (= for processing under milliseconds)
    assertTrue(updateDate.compareTo(beforeUpdateDate) >= 0);
}
 
开发者ID:nfl,项目名称:gold,代码行数:26,代码来源:GraphQLInstanceServiceTest.java

示例3: restore_state

import java.time.LocalDateTime; //导入方法依赖的package包/类
public boolean restore_state (InputObjectState os, int ot) {

        if (!super.restore_state(os, ot)
                || !restore_list(os, ot, pendingList)
                || !restore_list(os, ot, preparedList))
            return false;

        try {
            String s = os.unpackString();
            id = s == null ? null : new URL(s);
            s = os.unpackString();
            parentId = s == null ? null : new URL(s);
            clientId = os.unpackString();
            long millis = os.unpackLong();
            cancelOn = millis == 0 ? null : LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneOffset.UTC);
            status = os.unpackBoolean() ? CompensatorStatus.valueOf(os.unpackString()) : null;

            return true;
        } catch (IOException e) {
            if(LRALogger.logger.isDebugEnabled())
                LRALogger.logger.debugf(e, "Cannot restore state of objec type '%s'", ot);
            return false;
        }
    }
 
开发者ID:xstefank,项目名称:lra-service,代码行数:25,代码来源:Transaction.java

示例4: newDefectlogB_actionPerformed

import java.time.LocalDateTime; //导入方法依赖的package包/类
private void newDefectlogB_actionPerformed(ActionEvent e, String tasktext, Date startDate, Date endDate) { 
  	DefectLogDialog dlg = new DefectLogDialog(App.getFrame(), Local.getString("New Defect Log"));    	
  	Dimension frmSize = App.getFrame().getSize();
  	Point loc = App.getFrame().getLocation();
  	dlg.setLocation((frmSize.width - dlg.getSize().width) / 2 + loc.x, (frmSize.height - dlg.getSize().height) / 2 + loc.y);    	
dlg.setVisible(true);
 
if (dlg.CANCELLED)
  		return;
// create defect log
Date defectDate = (Date)dlg.date.getValue();
      LocalDateTime defectDateTime = LocalDateTime.ofInstant(defectDate.toInstant(), ZoneId.systemDefault());
      int defectNum = DefectLogManager.getDefectLogsForProject(CurrentProject.get()).size() + 1;
      int fixMin = (int)dlg.fixMin.getValue();
      int reference = (int)dlg.reference.getValue();
      PSP.Defect defectType = PSP.Defect.valueOf(dlg.defectType.getSelectedItem().toString());
      PSP.Phase injectPhase = PSP.Phase.valueOf(dlg.injectPhase.getSelectedItem().toString());
      PSP.Phase removePhase = PSP.Phase.valueOf(dlg.removePhase.getSelectedItem().toString());
      //PSP.Defect defectType = PSP.Defect.valueOf(PSP.reverseTypeConversion(dlg.defectType.getSelectedItem().toString(),0));
      //PSP.Phase injectPhase = PSP.Phase.valueOf(PSP.reverseConversion(dlg.injectPhase.getSelectedItem().toString(),0));
      //PSP.Phase removePhase = PSP.Phase.valueOf(PSP.reverseConversion(dlg.removePhase.getSelectedItem().toString(),0));
      String description = dlg.description.getText();
      
      		
      DefectLogManager.createDefectLog(defectDateTime, defectNum, defectType, injectPhase, removePhase, fixMin, reference, description);
saveDefectLogs();		
  }
 
开发者ID:ser316asu,项目名称:Neukoelln_SER316,代码行数:28,代码来源:DefectLogPanel.java

示例5: getMonthDifference

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 * Returns an integer which holds the difference of months between {@code fromDate} and {@code toDate}
 *
 * @param fromDate the date from which the difference is to be calculated
 * @param toDate   the date to which the difference is to be calculated
 * @return the difference of months between {@code fromDate} and {@code toDate}
 * if either of {@code fromDate} or {@code toDate} are null return null
 */
public static Integer getMonthDifference(Date fromDate, Date toDate) {

    if (fromDate == null || toDate == null)
        return null;
    Date localFromDate = new Date(fromDate.getTime());
    Date localToDate = new Date(toDate.getTime());

    LocalDateTime firstDate = LocalDateTime.ofInstant(localFromDate.toInstant(), ZoneId.systemDefault());
    LocalDateTime secondDate = LocalDateTime.ofInstant(localToDate.toInstant(), ZoneId.systemDefault());
    long months = Math.abs(ChronoUnit.MONTHS.between(firstDate, secondDate));
    return (int) months;
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:21,代码来源:DateFunctions.java

示例6: insertBuild

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static long insertBuild(Build build) {
    LOGGER.debug("Inserting build {} into the database.", build.getBuildId());

    Object start;
    Object finish;
    if (SqlHelper.isMySql()) {
        start = LocalDateTime.ofInstant(build.getTimer().getStartTime(), ZoneOffset.UTC);
        finish = LocalDateTime.ofInstant(build.getTimer().getFinishTime(), ZoneOffset.UTC);
    } else {
        start = OffsetDateTime.ofInstant(build.getTimer().getStartTime(), ZoneId.of(build.getTimer().getTimeZoneId()));
        finish = OffsetDateTime.ofInstant(build.getTimer().getFinishTime(), ZoneId.of(build.getTimer().getTimeZoneId()));
    }

    Object[] params = new Object[]{
            build.getBuildId(),
            build.getUserName(),
            build.getRootProjectName(),
            start,
            finish,
            build.getStatus(),
            build.getTagsAsSingleString()
    };

    Long generatedId = Yank.insertSQLKey("INSERT_BUILD", params);
    if (generatedId == 0) {
        throw new RuntimeException("Unable to save build record for " + build.getBuildId());
    }
    return generatedId;
}
 
开发者ID:gradle,项目名称:ge-export,代码行数:30,代码来源:BuildDAO.java

示例7: canParse

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Override
public boolean canParse(final String value) {
  try {
    LocalDateTime.ofInstant(Instant.ofEpochMilli(NumberUtils.createLong(value)),
        ZoneId.systemDefault());
    return true;
  } catch (final Exception e) {
    return false;
  }
}
 
开发者ID:stefanstaniAIM,项目名称:IPPR2016,代码行数:11,代码来源:JsonTimestampParser.java

示例8: javaToDosTime

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static long javaToDosTime(long time) {
    Instant instant = Instant.ofEpochMilli(time);
    LocalDateTime ldt = LocalDateTime.ofInstant(
            instant, ZoneId.systemDefault());
    int year = ldt.getYear() - 1980;
    if (year < 0) {
        return (1 << 21) | (1 << 16);
    }
    return (year << 25 |
        ldt.getMonthValue() << 21 |
        ldt.getDayOfMonth() << 16 |
        ldt.getHour() << 11 |
        ldt.getMinute() << 5 |
        ldt.getSecond() >> 1) & 0xffffffffL;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ZipUtils.java

示例9: nullSafeGet

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Override
public Object nullSafeGet(ResultSet resultSet, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    Object timestamp = StandardBasicTypes.TIMESTAMP.nullSafeGet(resultSet, names, session, owner);

    if (timestamp == null) {
        return null;
    }

    Date ts = (Date) timestamp;
    Instant instant = Instant.ofEpochMilli(ts.getTime());

    return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
}
 
开发者ID:lupindong,项目名称:xq_seckill_microservice,代码行数:15,代码来源:LocalDateTimeType.java

示例10: resolveInstantFromString

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 * Return a future instant from a string formatted #w#d#h#m
 * @param string String to resolve from
 * @return Instant in the future
 */
public static Instant resolveInstantFromString(String string) {
	Matcher matcher = Pattern.compile("\\d+|[wdhmWDHM]+").matcher(string);
	Instant now = Instant.now();
	LocalDateTime nowLDT = LocalDateTime.ofInstant(now, ZoneId.systemDefault());
	int previous = 0;
	while(matcher.find()) {
		String s = matcher.group().toLowerCase();
		if (Util.isInteger(s)) {
			previous = Integer.parseInt(s);
			continue;
		}
		switch(s) {
		case "w":
			nowLDT = nowLDT.plus(previous, ChronoUnit.WEEKS);
			break;
		case "d":
			nowLDT = nowLDT.plus(previous, ChronoUnit.DAYS);
			break;
		case "h":
			nowLDT = nowLDT.plus(previous, ChronoUnit.HOURS);
			break;
		case "m":
			nowLDT = nowLDT.plus(previous, ChronoUnit.MINUTES);
			break;
		default:
			break;
		}
	}
	return nowLDT.atZone(ZoneId.systemDefault()).toInstant();
}
 
开发者ID:paul-io,项目名称:momo-2,代码行数:36,代码来源:Util.java

示例11: addWeeksToDate

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 * Returns date with {@code weeks} added to {@code date}
 *
 * @param date       the date to which weeks are to be added
 * @param weeks weeks to be added to given {@code date}
 * @return date after adding {@code weeks} to {@code date}
 * if {@code date} is null then return null
 */
public static Date addWeeksToDate(Date date, int weeks) {
    if (date == null)
        return null;
    Date localDate = new Date(date.getTime());
    LocalDateTime localDateTime = LocalDateTime.ofInstant(localDate.toInstant(), ZoneId.systemDefault());
    Date newDate = Date.from(localDateTime.plusWeeks((long) weeks).atZone(ZoneId.systemDefault()).toInstant());
    return newDate;
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:17,代码来源:DateFunctions.java

示例12: nowHour

import java.time.LocalDateTime; //导入方法依赖的package包/类
private static String nowHour(long time, String formatter) {
    LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(time), ZoneId.systemDefault());
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(formatter);
    return localDateTime.format(dateTimeFormatter);
}
 
开发者ID:DreamYa0,项目名称:zeratul,代码行数:6,代码来源:DateUtils.java

示例13: factory_ofInstant_instantTooSmall

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofInstant_instantTooSmall() {
    LocalDateTime.ofInstant(Instant.MIN, OFFSET_PONE) ;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:TCKLocalDateTime.java

示例14: testLocalDateTime

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static void testLocalDateTime() {
        //使用默认时区时钟瞬时时间创建 Clock.systemDefaultZone() -->即相对于 ZoneId.systemDefault()默认时区  
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
//自定义时区  
        LocalDateTime now2 = LocalDateTime.now(ZoneId.of("Europe/Paris"));
        System.out.println(now2);//会以相应的时区显示日期  
//自定义时钟  
        Clock clock = Clock.system(ZoneId.of("Asia/Dhaka"));
        LocalDateTime now3 = LocalDateTime.now(clock);
        System.out.println(now3);//会以相应的时区显示日期  
//不需要写什么相对时间 如java.util.Date 年是相对于1900 月是从0开始  
//2013-12-31 23:59  
        LocalDateTime d1 = LocalDateTime.of(2013, 12, 31, 23, 59);
//年月日 时分秒 纳秒  
        LocalDateTime d2 = LocalDateTime.of(2013, 12, 31, 23, 59, 59, 11);
//使用瞬时时间 + 时区  
        Instant instant = Instant.now();
        LocalDateTime d3 = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault());
        System.out.println(d3);
//解析String--->LocalDateTime  
        LocalDateTime d4 = LocalDateTime.parse("2013-12-31T23:59");
        System.out.println(d4);
        LocalDateTime d5 = LocalDateTime.parse("2013-12-31T23:59:59.999");//999毫秒 等价于999000000纳秒  
        System.out.println(d5);
//使用DateTimeFormatter API 解析 和 格式化  
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        LocalDateTime d6 = LocalDateTime.parse("2013/12/31 23:59:59", formatter);
        System.out.println(formatter.format(d6));
//时间获取  
        System.out.println(d6.getYear());
        System.out.println(d6.getMonth());
        System.out.println(d6.getDayOfYear());
        System.out.println(d6.getDayOfMonth());
        System.out.println(d6.getDayOfWeek());
        System.out.println(d6.getHour());
        System.out.println(d6.getMinute());
        System.out.println(d6.getSecond());
        System.out.println(d6.getNano());
//时间增减  
        LocalDateTime d7 = d6.minusDays(1);
        LocalDateTime d8 = d7.plus(1, IsoFields.QUARTER_YEARS);
//LocalDate 即年月日 无时分秒  
//LocalTime即时分秒 无年月日  
//API和LocalDateTime类似就不演示了  
    }
 
开发者ID:juebanlin,项目名称:util4j,代码行数:47,代码来源:TimeIntroduction.java

示例15: map

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static LocalDateTime map(Date src, ZoneId zoneId) {
	return LocalDateTime.ofInstant(src.toInstant(), zoneId);
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:4,代码来源:Dates.java


注:本文中的java.time.LocalDateTime.ofInstant方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。