當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。