本文整理匯總了Java中org.joda.time.LocalDate.parse方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDate.parse方法的具體用法?Java LocalDate.parse怎麽用?Java LocalDate.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.joda.time.LocalDate
的用法示例。
在下文中一共展示了LocalDate.parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dateValidWithServiceResponseAsync
import org.joda.time.LocalDate; //導入方法依賴的package包/類
/**
* Get '2012-01-01' as date.
*
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable<ServiceResponse<Void>> dateValidWithServiceResponseAsync() {
final LocalDate datePath = LocalDate.parse("2012-01-01");
return service.dateValid(datePath)
.flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
@Override
public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
try {
ServiceResponse<Void> clientResponse = dateValidDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
示例2: dateValidWithServiceResponseAsync
import org.joda.time.LocalDate; //導入方法依賴的package包/類
/**
* Get '2012-01-01' as date.
*
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable<ServiceResponse<Void>> dateValidWithServiceResponseAsync() {
final LocalDate dateQuery = LocalDate.parse("2012-01-01");
return service.dateValid(dateQuery)
.flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
@Override
public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
try {
ServiceResponse<Void> clientResponse = dateValidDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
示例3: testJoda
import org.joda.time.LocalDate; //導入方法依賴的package包/類
@Test
public void testJoda()
{
DateTimeFormatter format = DateTimeFormat .forPattern("yyyy-MM-dd HH:mm:ss");
//時間解析
DateTime dateTime2 = DateTime.parse("2012-12-21 23:22:45", format);
//時間格式化,輸出==> 2012/12/21 23:22:45 Fri
String string_u = dateTime2.toString("yyyy/MM/dd HH:mm:ss EE");
System.out.println(string_u);
//格式化帶Locale,輸出==> 2012年12月21日 23:22:45 星期五
String string_c = dateTime2.toString("yyyy年MM月dd日 HH:mm:ss EE",Locale.CHINESE);
System.out.println(string_c);
LocalDate date = LocalDate.parse("2012-12-21 23:22:45", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
Date dates = date.toDate();
System.out.println(dates);
}
示例4: testAddJob
import org.joda.time.LocalDate; //導入方法依賴的package包/類
@Test
public void testAddJob()
{
ScheduleJobEntity job = new ScheduleJobEntity();
job.setJobName("test");
job.setJobGroup("test");
job.setCronExpression("*/5 * * * * ?");
job.setJobClassName("com.webside.quartz.job.EmailJob");
//java 8 實現方式
//LocalDate localDate = LocalDate.parse("2016-07-16 15:23:43",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
//Date date = Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
//joda實現方式
LocalDate localDate = LocalDate.parse("2016-07-16 15:23:43", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
Date date = localDate.toDate();
job.setStartDate(date);
job.setEndDate(localDate.plusDays(10).toDate());
scheduleJobService.addJob(job);
}
示例5: recordValueToJavaType
import org.joda.time.LocalDate; //導入方法依賴的package包/類
/**
* Take a string value retrieved from a {@link Record} and convert it to a java value of the specified
* type.
*
* @param stringValue The value retrieved from a {@link Record}.
* @param type The Java class to use for the result.
* @param <T> The Java type corresponding to the supplied Class
* @return The typed java value.
*/
@SuppressWarnings("unchecked")
public static <T> T recordValueToJavaType(String stringValue, Class<T> type) {
if (type == Integer.class) {
return (T)Integer.valueOf(stringValue);
} else if (type == Long.class) {
return (T)Long.valueOf(stringValue);
} else if (type == Boolean.class) {
return (T)Boolean.valueOf(stringValue);
} else if (type == LocalDate.class) {
return (T)LocalDate.parse(stringValue, FROM_YYYY_MM_DD);
} else if (type == Double.class) {
return (T)Double.valueOf(stringValue);
} else {
return (T)stringValue;
}
}
示例6: formatDate
import org.joda.time.LocalDate; //導入方法依賴的package包/類
private void formatDate( String date, String datePattern ) {
DateTimeFormatter customDateFormatter = DateTimeFormat.forPattern( datePattern );
String dateString = date;
if ( date != null ) {
dateString = date;
// dateString should already be padded with zeros before being parsed
myDate = date == null ? null : LocalDate.parse( dateString, customDateFormatter );
dt = dt.withDate( myDate.getYear(), myDate.getMonthOfYear(), myDate.getDayOfMonth() );
}
}
示例7: formatDate
import org.joda.time.LocalDate; //導入方法依賴的package包/類
private void formatDate( String date, String datePattern ) {
DateTimeFormatter customDateFormatter = DateTimeFormat.forPattern( datePattern );
String dateString = date;
if ( date != null && !myDate.equals( "" ) ) {
dateString = date;
// dateString should already be padded with zeros before being parsed
myDate = date == null ? null : LocalDate.parse( dateString, customDateFormatter );
dt = dt.withDate( myDate.getYear(), myDate.getMonthOfYear(), myDate.getDayOfMonth() );
}
}
示例8: parse
import org.joda.time.LocalDate; //導入方法依賴的package包/類
/**
* 使用joda替代jdk自帶的日期格式化類,因為 DateFormat 和 SimpleDateFormat 類不都是線程安全的
* 確保不會在多線程狀態下使用同一個 DateFormat 或者 SimpleDateFormat 實例
* 如果多線程情況下需要訪問同一個實例,那麽請用同步方法
* 可以使用 joda-time 日期時間處理庫來避免這些問題,如果使用java 8, 請切換到 java.time包
* 你也可以使用 commons-lang 包中的 FastDateFormat 工具類
* 另外你也可以使用 ThreadLocal 來處理這個問題
*/
@Override
public Date parse(String text, Locale locale) throws ParseException {
Date date = null;
LocalDate localDate = null;
try {
localDate = LocalDate.parse(text, DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
date = localDate.toDate();
} catch (Exception e) {
localDate = LocalDate.parse(text, DateTimeFormat.forPattern("yyyy-MM-dd"));
date = localDate.toDate();
throw e;
}
return date;
}
示例9: getStartAndEndDates
import org.joda.time.LocalDate; //導入方法依賴的package包/類
/**
* Parses ISO8601 formatted Date Strings.
* @param start If start is null then defaults to 1 month
* @param end If end is null then it defaults to now();
*/
public static Pair<LocalDate, LocalDate> getStartAndEndDates(String start, String end)
{
if (start == null) return null;
LocalDate startDate = LocalDate.parse(start);
LocalDate endDate = end!=null?LocalDate.parse(end):LocalDate.now();
return new Pair<LocalDate, LocalDate>(startDate, endDate);
}
示例10: sanitize
import org.joda.time.LocalDate; //導入方法依賴的package包/類
private Http.Request sanitize(Http.Context ctx, JsonNode body) throws SanitizingException {
if (body.has("date")) {
LocalDate date = LocalDate.parse(body.get("date").asText(), ISODateTimeFormat.dateTimeParser());
return ctx.request().addAttr(Attrs.DATE, date);
} else {
throw new SanitizingException("no date");
}
}
示例11: postProcessSlots
import org.joda.time.LocalDate; //導入方法依賴的package包/類
private Set<TimeSlot> postProcessSlots(JsonNode node, String date, Exam exam, User user) {
// Filter out slots that user has a conflicting reservation with
if (node.isArray()) {
ArrayNode root = (ArrayNode) node;
LocalDate searchDate = LocalDate.parse(date, ISODateTimeFormat.dateParser());
// users reservations starting from now
List<Reservation> reservations = Ebean.find(Reservation.class)
.fetch("enrolment.exam")
.where()
.eq("user", user)
.gt("startAt", searchDate.toDate())
.findList();
DateTimeFormatter dtf = ISODateTimeFormat.dateTimeParser();
Stream<JsonNode> stream = StreamSupport.stream(root.spliterator(), false);
Map<Interval, Optional<Integer>> map = stream.collect(Collectors.toMap(n -> {
DateTime start = dtf.parseDateTime(n.get("start").asText());
DateTime end = dtf.parseDateTime(n.get("end").asText());
return new Interval(start, end);
}, n -> Optional.of(n.get("availableMachines").asInt()),
(u, v) -> {
throw new IllegalStateException(String.format("Duplicate key %s", u));
},
LinkedHashMap::new));
return handleReservations(map, reservations, exam, null, user);
}
return Collections.emptySet();
}
示例12: getEndSearchDate
import org.joda.time.LocalDate; //導入方法依賴的package包/類
/**
* @return which one is sooner, exam period's end or week's end
*/
private static LocalDate getEndSearchDate(String endDate, LocalDate searchDate) {
LocalDate endOfWeek = searchDate.dayOfWeek().withMaximumValue();
LocalDate examEnd = LocalDate.parse(endDate, ISODateTimeFormat.dateTimeParser());
String reservationWindow = SettingsController.getOrCreateSettings(
"reservation_window_size", null, null).getValue();
int windowSize = 0;
if (reservationWindow != null) {
windowSize = Integer.parseInt(reservationWindow);
}
LocalDate reservationWindowDate = LocalDate.now().plusDays(windowSize);
LocalDate endOfSearchDate = examEnd.isBefore(reservationWindowDate) ? examEnd : reservationWindowDate;
return endOfWeek.isBefore(endOfSearchDate) ? endOfWeek : endOfSearchDate;
}
示例13: formatDate
import org.joda.time.LocalDate; //導入方法依賴的package包/類
private void formatDate( String date, String datePattern ) {
DateTimeFormatter customDateFormatter = DateTimeFormat.forPattern( datePattern );
// Note that date should already match datePattern format before parsing
myDate = date == null ? null : LocalDate.parse( date, customDateFormatter );
myDateTime = myDateTime.withDate( myDate.getYear(), myDate.getMonthOfYear(), myDate.getDayOfMonth() );
}
示例14: deserialize
import org.joda.time.LocalDate; //導入方法依賴的package包/類
@Override
public LocalDate deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return LocalDate.parse(json.getAsString());
}
示例15: setAsText
import org.joda.time.LocalDate; //導入方法依賴的package包/類
@Override
public void setAsText(String arg0) throws IllegalArgumentException {
LocalDate localDate = LocalDate.parse(arg0,DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
this.setValue(localDate.toDate());
}