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


Java LocalDateTime.parse方法代码示例

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


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

示例1: testCreateDefectLog

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void testCreateDefectLog() {
	PSP.root = root1;
	
	// Normal creation, should yield no problems
	LocalDateTime date = LocalDateTime.parse("2017-04-11 14:34", DateTimeFormatter.ofPattern(DATE_FORMAT));
	DefectLog log1 = DefectLogManager.createDefectLog(date, 1, PSP.Defect.Data, PSP.Phase.Code, PSP.Phase.Code, 3, 1, "hi mom!");
	assertNotNull(log1);
	assertEquals(log1.getDescription(), "hi mom!");
	
	// Null reference - should throw exception
	boolean exThrown = false;
	try {
		DefectLog log2 = DefectLogManager.createDefectLog(null, 2, PSP.Defect.Assignment, PSP.Phase.Code, PSP.Phase.Code, 3, 1, "hi mom!");
	} catch (NullPointerException e) {
		exThrown = true;
	} catch (Exception e2) {
		// don't do anything??
	}
	assertTrue(exThrown);
	
}
 
开发者ID:ser316asu,项目名称:Neukoelln_SER316,代码行数:23,代码来源:DefectLogManagerTest.java

示例2: deserialize

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Override
public LocalDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException
{
    if (parser.hasTokenId(JsonTokenId.ID_STRING)) {
        String string = parser.getText().trim();
        if (string.length() == 0) {
            return null;
        }
        
        try {
            return LocalDateTime.parse(string, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        } catch (DateTimeException e) {
            throw new IOException(e);
        }
    }
    if (parser.hasTokenId(JsonTokenId.ID_EMBEDDED_OBJECT)) {
        return (LocalDateTime) parser.getEmbeddedObject();
    }
    throw context.wrongTokenException(parser, JsonToken.VALUE_STRING, "Expected string.");
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:21,代码来源:LocalDateTimeDeserializer.java

示例3: parseDate

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static LocalDateTime parseDate(String date) {
    Objects.requireNonNull(date, "date");

    for (DateTimeFormatter formatter : DATE_FORMATTERS) {
        try {
            // equals ISO_LOCAL_DATE
            if (formatter.equals(DATE_FORMATTERS.get(2))) {
                LocalDate localDate = LocalDate.parse(date, formatter);

                return localDate.atStartOfDay();
            } else {
                return LocalDateTime.parse(date, formatter);
            }
        } catch (java.time.format.DateTimeParseException ignored) {
        }
    }

    return null;
}
 
开发者ID:donbeave,项目名称:graphql-java-datetime,代码行数:20,代码来源:DateTimeHelper.java

示例4: parseDate

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static LocalDateTime parseDate(String str) throws ParseException {
    if (str==null) return null;
    // LSF puts in spaces for text alignment purposes instead of padding with zeros. These unfortunately break the
    // date parser. The following is a relatively naive way to try to fix this, but it should work for all cases
    // that we care about:
    str = str.trim().replaceAll("  ", " 0");
    // Remove the E for "Estimated" and other such characters from the end of dates.
    str = str.replaceAll("( \\w)$", "");
    // If necessary, add the current year (necessary before the 10.1.0.3 service pack)
    String dateStr = str;
    if (!dateStr.matches(".*\\d{4}")) {
        dateStr = dateStr + " " + LocalDateTime.now().getYear();
    }
    if (dateStr.matches(".*\\d{2}:\\d{2}:\\d{2}.*")) {
        return LocalDateTime.parse(dateStr, DATE_FORMAT_SECS);
    }
    return LocalDateTime.parse(dateStr, DATE_FORMAT);
}
 
开发者ID:JaneliaSciComp,项目名称:java-lsf,代码行数:19,代码来源:LsfUtils.java

示例5: main

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static void main(String[] args) {
    LocalDate date = LocalDate.of(2052, 01, 31);
    System.out.println(date.minus(Period.ofDays(1)));

    // Because Period instances can represent positive or negative periods
    // (like 15 days and -15 days), you can subtract days from a LocalDate or
    // LocalDateTime by calling the method plus
    System.out.println(date.plus(Period.ofDays(-1)));

    // Similarly, the method minus() with the classes LocalDate and LocalDateTime
    // to subtract a period of years, month, weeks, or days
    LocalDateTime dateTime = LocalDateTime.parse("2020-01-31T14:18:36");
    System.out.println(dateTime.minus(Period.ofYears(2)));

    LocalDate localDate = LocalDate.of(2052, 01, 31);
    System.out.println(localDate.minus(Period.ofWeeks(4)));

}
 
开发者ID:huby,项目名称:java-se8-oca-study-guide,代码行数:19,代码来源:Main.java

示例6: main

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static void main(String[] args) {
    LocalDateTime prizeCeremony = LocalDateTime.parse("2050-06-05T14:00:00");
    LocalDateTime dateTimeNow = LocalDateTime.now();

    if (prizeCeremony.getMonthValue() == 6)
        System.out.println("Can't invite president");
    else
        System.out.println("President invited");

    LocalDateTime chiefGuestDeparture = LocalDateTime.parse("2050-06-05T14:30:00");

    if (prizeCeremony.plusHours(2).isAfter(chiefGuestDeparture))
        System.out.println("Chief Guest will leave before ceremony completes");

    LocalDateTime eventMgrArrival = LocalDateTime.of(2050, 6, 5, 14, 14, 30, 0);
    if (eventMgrArrival.isAfter(prizeCeremony.minusHours(3)))
        System.out.println("Manager is supposed to arrive 3 hrs earlier");
}
 
开发者ID:huby,项目名称:java-se8-oca-study-guide,代码行数:19,代码来源:Main.java

示例7: resolveDate

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 * Helper method for resolving local date time. If the key to the data object doesn´t specify hours and minutes it
 * returns the hour at beginning of that day.
 *
 * @param key the key to the data object, i.e: "2017-12-01 11:15" or "2017-12-01" depending on interval
 * @return the {@link LocalDateTime} instance
 */
protected LocalDateTime resolveDate(String key) {
  switch (interval) {
    case MONTHLY:
    case WEEKLY:
    case DAILY:
      return LocalDate.parse(key, SIMPLE_DATE_FORMAT).atStartOfDay();
    default:
      return LocalDateTime.parse(key, DATE_WITH_SIMPLE_TIME_FORMAT);
  }
}
 
开发者ID:patriques82,项目名称:alphavantage4j,代码行数:18,代码来源:TechnicalIndicatorParser.java

示例8: testfromBytesButDoNotSet

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void testfromBytesButDoNotSet(){
	String dateStr1 = "2016-06-22 19:20:14.100123456";
	String dateStr2 = "2014-06-24 03:20:14.210998531";
	DateTimeFormatter formatterWithNano = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS");;
	LocalDateTime localDateTime1 = LocalDateTime.parse(dateStr1, formatterWithNano);
	LocalDateTime localDateTime2 = LocalDateTime.parse(dateStr2, formatterWithNano);
	LocalDateTimeField field1 = new LocalDateTimeField(new LocalDateTimeFieldKey("test"), localDateTime1);
	LocalDateTimeField field2 = new LocalDateTimeField(new LocalDateTimeFieldKey("test"), localDateTime2);
	LocalDateTime localDateTimeFromBytes1 = field1.fromBytesButDoNotSet(field1.getBytes(), 0);
	LocalDateTime localDateTimeFromBytes2 = field2.fromBytesButDoNotSet(field2.getBytes(), 0);
	Assert.assertEquals(field1.getTruncatedLocalDateTime(localDateTime1), localDateTimeFromBytes1);
	Assert.assertEquals(field2.getTruncatedLocalDateTime(localDateTime2), localDateTimeFromBytes2);
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:15,代码来源:LocalDateTimeField.java

示例9: build

import java.time.LocalDateTime; //导入方法依赖的package包/类
public void build() {

        Objects.requireNonNull(year);
        Objects.requireNonNull(month);
        Objects.requireNonNull(dayOfMonth);
        Objects.requireNonNull(hour);
        Objects.requireNonNull(minute);

        StringBuilder dateString = new StringBuilder();
        dateString.append(year);
        dateString.append("-");
        dateString.append(month);
        dateString.append("-");
        dateString.append(dayOfMonth);
        dateString.append("T");
        dateString.append(hour);
        dateString.append(":");
        dateString.append(minute);
        dateString.append(":");
        dateString.append(second);

        if (nanosecond != null) {
            dateString.append(".").append(nanosecond);
        }

        if (zoneOffset != null) {
            dateString.append(zoneOffset);
        }

        if (zoneId != null) {
            dateString.append(zoneId.trim());
        }

        boolean isZonedDateTime = zoneOffset != null || zoneId != null;
        Temporal dateTime = isZonedDateTime ?
                ZonedDateTime.parse(dateString.toString(), DateTimeFormatter.ISO_ZONED_DATE_TIME)
                : LocalDateTime.parse(dateString.toString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME);

        set(dateTime);
    }
 
开发者ID:edmocosta,项目名称:queryfy,代码行数:41,代码来源:DateTimeVar.java

示例10: factory_parse_formatter_nullText

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
    LocalDateTime.parse((String) null, f);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TCKLocalDateTime.java

示例11: unmarshal

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Nullable
@Override
public LocalDateTime unmarshal(String v) {
	return isEmpty(v) ? null : LocalDateTime.parse(v);
}
 
开发者ID:dvbern,项目名称:date-helper,代码行数:6,代码来源:LocalDateTimeXMLConverter.java

示例12: decodeText

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Override
public LocalDateTime decodeText(int len, ByteBuf buff) {
  CharSequence cs = buff.readCharSequence(len, StandardCharsets.UTF_8);
  return LocalDateTime.parse(cs, TIMESTAMP_FORMAT);
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:6,代码来源:DataType.java

示例13: read

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Override
public LocalDateTime read(JsonReader in) throws IOException {
    return LocalDateTime.parse(in.nextString());
}
 
开发者ID:CROW-NDOV,项目名称:displaydirect,代码行数:5,代码来源:DateTimeAdapter.java

示例14: setUp

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
	// get testing values
	estimatePhase = PSP.Phase.Code.toString();
	actualPhase = PSP.Phase.Code.toString();
	estimateMin = String.valueOf(90);
	actualMin = String.valueOf(120);
	// prep values
	int estimateLoc = 0;
	DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
	String actualTimeStart = "2017-04-07 08:00";
	LocalDateTime timeStart = LocalDateTime.parse(actualTimeStart, formatter);
	LocalDateTime timeStop = timeStart.plusMinutes(Integer.parseInt(actualMin));
	String actualTimeStop = timeStop.format(formatter);
	// set testing values
	Project project = ProjectManager.createProject("1","FirstProject",new CalendarDate(1,1,2017),new CalendarDate(1,1,2018));
	Element root = new Element("psp");
	Element projectNode = new Element(PSP.ELEMENT_NAME);
	projectNode.addAttribute(new Attribute(PSP.ID_ATTRIBUTE, project.getID()));
	// estimates
	Element listNode = new Element(EstimateManager.ELEMENT_NAME);
	Element estimateNode = new Element(EstimateManager.CHILD_ELEMENT);
	estimateNode.addAttribute(new Attribute("module","test module"));
	estimateNode.addAttribute(new Attribute("loc", String.valueOf(estimateLoc)));
	estimateNode.addAttribute(new Attribute("phase", estimatePhase.toString()));
	estimateNode.addAttribute(new Attribute("minutes", String.valueOf(estimateMin)));
	estimateNode.addAttribute(new Attribute("comments","this is a test"));		
	// time logs
	Element timeloglistNode = new Element("timeloglist");
	Element yearNode = new Element("year");
	yearNode.addAttribute(new Attribute("year", "2017"));
	Element monthNode = new Element("month");
	monthNode.addAttribute(new Attribute("month", "1"));
	Element dayNode = new Element("day");
	dayNode.addAttribute(new Attribute("day","1"));
	dayNode.addAttribute(new Attribute("date", "1/1/2017"));
	Element timelog = new Element("timelog");
	timelog.addAttribute(new Attribute("id","1"));
	timelog.addAttribute(new Attribute("phase", actualPhase.toString()));
	timelog.addAttribute(new Attribute("interruption","0"));
	timelog.addAttribute(new Attribute("comments","test"));
	timelog.addAttribute(new Attribute("timestart",actualTimeStart));
	timelog.addAttribute(new Attribute("timestop",actualTimeStop));
	// build xml
	root.appendChild(projectNode);
	projectNode.appendChild(listNode);
	projectNode.appendChild(timeloglistNode);
	listNode.appendChild(estimateNode);
	timeloglistNode.appendChild(yearNode);
	yearNode.appendChild(monthNode);
	monthNode.appendChild(dayNode);
	dayNode.appendChild(timelog);
	PSP.root = root;
	testTimeTable = new TimeSummaryTable();
	CurrentProject.set(project);
}
 
开发者ID:ser316asu,项目名称:Neukoelln_SER316,代码行数:57,代码来源:TimeSummaryTableTest.java

示例15: fromTaken

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static LocalDateTime fromTaken(String dateTime){
    return dateTime==null ? null : LocalDateTime.parse(dateTime, PICTURE_FORMATTER);
}
 
开发者ID:erikcostlow,项目名称:PiCameraProject,代码行数:4,代码来源:Formats.java


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