本文整理汇总了Java中java.time.LocalDate.parse方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDate.parse方法的具体用法?Java LocalDate.parse怎么用?Java LocalDate.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDate
的用法示例。
在下文中一共展示了LocalDate.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: between
import java.time.LocalDate; //导入方法依赖的package包/类
@GET
@Path("/between/{start}/{end}")
@Produces(MediaType.APPLICATION_JSON)
public List<PictureThumb> between(@PathParam("start") String start, @PathParam("end") String end){
System.out.println("Between " + start + " and " + end);
final LocalDate startDate = LocalDate.parse(start, DateTimeFormatter.ISO_DATE);
final LocalDate endDate = LocalDate.parse(end, DateTimeFormatter.ISO_DATE);
final List<PictureThumb> retval = new ArrayList<>();
try {
Files.list(IMAGES_ROOT)
//.filter(p -> p.getFileName().toString().startsWith(start))
.filter(p -> p.getFileName().toString().endsWith(".jpeg"))
.sorted()
.map(ImagesEndpoint::convert)
.forEach(retval::add);
} catch (IOException ex) {
Logger.getLogger(ImagesEndpoint.class.getName()).log(Level.SEVERE, null, ex);
}
return retval;
}
示例2: test_parse_resolve_localizedWom
import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWom(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField womField = week.weekOfMonth();
for (int i = 1; i <= 60; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(MONTH_OF_YEAR).appendLiteral(':')
.appendValue(womField).appendLiteral(':')
.appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(SMART);
String str = date.getYear() + ":" + date.getMonthValue() + ":" +
date.get(womField) + ":" + date.get(DAY_OF_WEEK);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date, " ::" + str + "::" + i);
date = date.plusDays(1);
}
}
示例3: test_parse_resolve_localizedWoyDow_lenient
import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoyDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 15);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
TemporalField woyField = week.weekOfYear();
for (int i = 1; i <= 60; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(woyField).appendLiteral(':')
.appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
int woy = date.get(woyField);
int dow = date.get(dowField);
for (int j = woy - 60; j < woy + 60; j++) {
String str = date.getYear() + ":" + j + ":" + dow;
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date.plusWeeks(j - woy), " ::" + str + ": :" + i + "::" + j);
}
date = date.plusDays(1);
}
}
示例4: test_parse_resolve_localizedWoWBY_lenient
import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBY_lenient(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate date = LocalDate.of(2012, 12, 31);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField wowbyField = week.weekOfWeekBasedYear();
TemporalField yowbyField = week.weekBasedYear();
for (int i = 1; i <= 60; i++) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(yowbyField).appendLiteral(':')
.appendValue(wowbyField).appendLiteral(':')
.appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(LENIENT);
int wowby = date.get(wowbyField);
int dow = date.get(DAY_OF_WEEK);
for (int j = wowby - 60; j < wowby + 60; j++) {
String str = date.get(yowbyField) + ":" + j + ":" + dow;
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, date.plusWeeks(j - wowby), " ::" + str + ": :" + i + "::" + j);
}
date = date.plusDays(1);
}
}
示例5: test_parse_resolve_localizedWoWBY_strict
import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBY_strict(DayOfWeek firstDayOfWeek, int minDays) {
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField wowbyField = week.weekOfWeekBasedYear();
TemporalField yowbyField = week.weekBasedYear();
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(yowbyField).appendLiteral(':')
.appendValue(wowbyField).appendLiteral(':')
.appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(STRICT);
String str = "2012:0:1";
try {
LocalDate date = LocalDate.parse(str, f);
assertEquals(date.get(yowbyField), 2012);
assertEquals(date.get(wowbyField), 0);
assertEquals(date.get(DAY_OF_WEEK), 1);
} catch (DateTimeException ex) {
// expected
}
}
示例6: getCurrentSpotRosterView
import java.time.LocalDate; //导入方法依赖的package包/类
@Override
@Transactional
public SpotRosterView getCurrentSpotRosterView(Integer tenantId) {
List<TimeSlot> timeSlotList = entityManager.createNamedQuery("TimeSlot.findAll", TimeSlot.class)
.setParameter("tenantId", tenantId)
.getResultList();
LocalDate startDate;
LocalDate endDate;
if (timeSlotList.isEmpty()) {
startDate = LocalDate.parse("1900-01-01");
endDate = LocalDate.parse("2900-01-01");
} else {
startDate = timeSlotList.get(0).getStartDateTime().toLocalDate();
endDate = timeSlotList.get(timeSlotList.size() - 1).getStartDateTime().toLocalDate();
}
return getSpotRosterView(tenantId, startDate, endDate, entityManager.createNamedQuery("Spot.findAll",
Spot.class)
.setParameter("tenantId", tenantId)
.getResultList());
}
示例7: createEmployee
import java.time.LocalDate; //导入方法依赖的package包/类
private static Employee createEmployee() throws Exception {
// Get the employee info from the command prompt
System.out.println("Please, input the employee info:");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Name: ");
String name = reader.readLine();
System.out.print("Date of Birth (yyyy-MM-dd): ");
String dob = reader.readLine();
LocalDate dobDate = LocalDate.parse(dob, formatter);
System.out.print("Address: ");
String address = reader.readLine();
System.out.print("Salary: ");
double salary = Double.parseDouble(reader.readLine());
System.out.print("Do you want to add a photo? (Y/N): ");
String yesNo = reader.readLine();
byte[] bytesBlob = null;
// Insert new record: begin
if (yesNo.equalsIgnoreCase("Y")) {
// With photo
System.out.print("Type the file name as it appears in folder /photos, including extension: ");
String fileName = reader.readLine();
File photo = new File("./photos/" + fileName);
InputStream streamBlob = new FileInputStream(photo);
bytesBlob = new byte[streamBlob.available()];
}
// Create the object
Employee emp = new Employee(name, dobDate, address, salary, bytesBlob, null);
// Begin transaction
em.getTransaction().begin();
// Store the object
em.persist(emp);
// End transaction
em.getTransaction().commit();
// Return the Employee
return emp;
}
示例8: convertFactValue
import java.time.LocalDate; //导入方法依赖的package包/类
private FactValue convertFactValue(Tokens tokens)
{
FactValue fv = null;
switch(tokens.tokensString)
{
case "De":
fv = FactValue.parse(tokens.tokensList.get(0));
break;
case "No":
fv = FactValue.parse(tokens.tokensList.get(0));
break;
case "Da":
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/M/yyyy");
LocalDate factValueInDate = LocalDate.parse(tokens.tokensList.get(0), formatter);
fv = FactValue.parse(factValueInDate);
break;
case "Url":
fv = FactValue.parseURL(tokens.tokensList.get(0));
break;
case "Id":
fv = FactValue.parseUUID(tokens.tokensList.get(0));
break;
case "Ha":
fv = FactValue.parseHash(tokens.tokensList.get(0));
}
return fv;
}
示例9: test_parse_weeks_LENIENT
import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider="week")
public void test_parse_weeks_LENIENT(LocalDate date, DayOfWeek dow, int week, int wby) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral('-')
.appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral('-')
.appendValue(DAY_OF_WEEK)
.toFormatter().withResolverStyle(ResolverStyle.LENIENT);
LocalDate parsed = LocalDate.parse(wby + "-" + week + "-" + dow.getValue(), f);
assertEquals(parsed, date);
}
示例10: parse
import java.time.LocalDate; //导入方法依赖的package包/类
@Override
public Map<String, String> parse(String content) throws ParserException {
Map<String, String> extra = new HashMap<>();
try {
LocalDate date = LocalDate.parse(content, marc);
extra.put("normalized", date.format(iso));
} catch(DateTimeParseException e) {
throw new ParserException(String.format(
"Invalid content: '%s'. %s", content, e.getMessage()));
}
return extra;
}
示例11: weekly
import java.time.LocalDate; //导入方法依赖的package包/类
@Override
public LinkedHashMap<LocalDate, Stock> weekly(String symbol, HashMap<String, String> options) throws UnsupportedEncodingException, InvalidApiKeyException, InvalidFunctionOptionException, MalFormattedFunctionException, MissingApiKeyException, UltraHighFrequencyRequestException {
String function = "TIME_SERIES_WEEKLY";
String queryString = ALPHA_VANTAGE_API_URL + "function=" + function + "&symbol=" + symbol + "&apikey=" + apiKey + "&";
String encodedUrl = options.keySet().stream().map(key -> {
try {
return key + "=" + UriUtils.encode(options.get(key), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}).collect(joining("&", queryString, ""));
LinkedHashMap<LocalDate, Stock> result = new LinkedHashMap<>();
JsonNode jsonNode = restTemplate.getForObject(encodedUrl, JsonNode.class);
Iterator<Map.Entry<String, JsonNode>> it = jsonNode.fields();
while (it.hasNext()) {
Map.Entry<String, JsonNode> mapEntry = it.next();
ExceptionUtil.handleException(mapEntry, function);
if (mapEntry.getKey().equals("Weekly Time Series")) {
JsonNode node = mapEntry.getValue();
Iterator<Map.Entry<String, JsonNode>> timeSeriesIter = node.fields();
while (timeSeriesIter.hasNext()) {
Map.Entry<String, JsonNode> timeSeriesMap = timeSeriesIter.next();
LocalDate localDate = LocalDate.parse(timeSeriesMap.getKey(), DateTimeFormatter.ISO_LOCAL_DATE);
String open = String.valueOf(timeSeriesMap.getValue().get("1. open")).replaceAll("\"", "");
String high = String.valueOf(timeSeriesMap.getValue().get("2. high")).replaceAll("\"", "");
String low = String.valueOf(timeSeriesMap.getValue().get("3. low")).replaceAll("\"", "");
String close = String.valueOf(timeSeriesMap.getValue().get("4. close")).replaceAll("\"", "");
String volume = String.valueOf(timeSeriesMap.getValue().get("5. volume")).replaceAll("\"", "");
result.put(localDate, Stock.newStpckInstance(symbol, open, high, low, close, volume));
}
}
}
return result;
}
示例12: test_parse_parseLenientQuarter_LENIENT
import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider = "parseLenientQuarter")
public void test_parse_parseLenientQuarter_LENIENT(String str, LocalDate expected, boolean smart) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(YEAR).appendLiteral(':')
.appendValue(IsoFields.QUARTER_OF_YEAR).appendLiteral(':')
.appendValue(IsoFields.DAY_OF_QUARTER)
.toFormatter().withResolverStyle(ResolverStyle.LENIENT);
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, expected);
}
示例13: factory_parse_formatter_nullFormatter
import java.time.LocalDate; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullFormatter() {
LocalDate.parse("ANY", null);
}
示例14: unmarshal
import java.time.LocalDate; //导入方法依赖的package包/类
@Override
public LocalDate unmarshal(String date)
{
return LocalDate.parse(date.substring(0, 10));
}
示例15: deleteMessage
import java.time.LocalDate; //导入方法依赖的package包/类
private static RealtimeMessage deleteMessage(Kv78Packet packet, Map<String, String> r) {
return new DeleteMessage(r.get("DataOwnerCode"), LocalDate.parse(r.get("MessageCodeDate")),
Integer.valueOf(r.get("MessageCodeNumber")), r.get("TimingPointCode")); //r.get("TimingPointDataOwnerCode")
}