Here you can find the source of parseAscTime(String date)
Parameter | Description |
---|---|
date | The string Asc format. |
public static DateTime parseAscTime(String date)
//package com.java2s; /*/* w w w . ja va 2 s .co m*/ * Copyright 2012 Johns Hopkins University * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; public class Main { private static final String ASC_FORMAT = "EEE MMM dd HH:mm:ss yyyy"; /** * Parses an ASC formatted date string into a DateTime object * @param date The string Asc format. * @return A DateTime object representing the date in the string, or null if the string isn't properly formatted. */ public static DateTime parseAscTime(String date) { DateTime dateTime = null; try { Date parsedDate = getDateFormat(ASC_FORMAT).parse(date); dateTime = new DateTime(parsedDate.getTime()).withZone(DateTimeZone.forID("GMT")); } catch (ParseException e) { //The string was not formatted correctly, ensure null is returned dateTime = null; } return dateTime; } private static DateFormat getDateFormat(String format) { DateFormat fmt = new SimpleDateFormat(format); fmt.setTimeZone(TimeZone.getTimeZone("GMT")); return fmt; } }