Here you can find the source of parseDate(String value)
Parameter | Description |
---|---|
value | the date expression to be parsed. |
public static Date parseDate(String value)
//package com.java2s; /*// w ww.j a va 2 s . c o m * Licensed to the Indoqa Software Design und Beratung GmbH (Indoqa) under * one or more contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright ownership. * Indoqa licenses this file to You 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; public class Main { private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; private static final TimeZone TIME_ZONE = TimeZone.getTimeZone("UTC"); /** * Parse a date expression with both date and time information with full millisecond precision and create a {@link Date}. The * assumed time zone is always UTC. * * This method accepts date expressions generated with {@link #formatDate(Date)}. * * @param value the date expression to be parsed. * @return The parsed date. */ public static Date parseDate(String value) { try { return createDateFormat().parse(value); } catch (ParseException e) { throw new IllegalArgumentException("Failed to parse date expression '" + value + "'", e); } } private static DateFormat createDateFormat() { DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); dateFormat.setTimeZone(TIME_ZONE); return dateFormat; } }