Parses the given date string in the XEP-0082 - XMPP Date and Time Profiles format. - Java java.lang

Java examples for java.lang:String Format

Description

Parses the given date string in the XEP-0082 - XMPP Date and Time Profiles format.

Demo Code

/**/*  w w w  . j  a  va 2s  .  c om*/
 * $RCSfile$
 * $Revision: 11823 $
 * $Date: 2010-08-15 08:20:48 -0500 (Sun, 15 Aug 2010) $
 *
 * Copyright 2003-2007 Jive Software.
 *
 * All rights reserved. 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.
 */
//package com.java2s;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    /**
     * Date format as defined in XEP-0082 - XMPP Date and Time Profiles. The time zone is set to
     * UTC.
     * <p>
     * Date formats are not synchronized. Since multiple threads access the format concurrently, it
     * must be synchronized externally or you can use the convenience methods
     * {@link #parseXEP0082Date(String)} and {@link #formatXEP0082Date(Date)}.
     */
    public static final DateFormat XEP_0082_UTC_FORMAT = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

    /**
     * Parses the given date string in the XEP-0082 - XMPP Date and Time Profiles format.
     * 
     * @param dateString the date string to parse
     * @return the parsed Date
     * @throws ParseException if the specified string cannot be parsed
     */
    public static Date parseXEP0082Date(String dateString)
            throws ParseException {
        synchronized (XEP_0082_UTC_FORMAT) {
            return XEP_0082_UTC_FORMAT.parse(dateString);
        }
    }
}

Related Tutorials