Here you can find the source of parseDateHMSMZ(String dateString)
Parameter | Description |
---|---|
dateString | The date string to convert, must be one of the above. |
Parameter | Description |
---|---|
ParseException | If the format does not match. |
public static Date parseDateHMSMZ(String dateString) throws ParseException
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Firestar Software, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:// w w w.j av a 2 s . c o m * Firestar Software, Inc. - initial API and implementation * * Author: * Gabriel Oancea * *******************************************************************************/ import java.util.*; import java.text.*; public class Main { private static final SimpleDateFormat HMSMZ = new SimpleDateFormat( "HH:mm:ss.SSSZ"); /** * Transform the XML Schema format for the timezone to Java format. * <p> * <code>0123456789012345678901234567890</code> * <p> * <code>HH:mm:ss.SSS-05:00</code> to * <p> * <code>HH:mm:ss.SSS-0500</code> * <p> * and * <p> * <code>HH:mm:ss.SSSZ</code> to * <p> * <code>HH:mm:ss.SSS-0000</code> * <p> * * @param dateString The date string to convert, must be one of the above. * @return The date parsed. * @throws ParseException If the format does not match. */ public static Date parseDateHMSMZ(String dateString) throws ParseException { if (dateString == null || dateString.length() < 12) throw new IllegalArgumentException("Invalid date string " + dateString); if (dateString.length() == 12) // tz missing dateString += "-0000"; else if (dateString.length() == 13 && dateString.endsWith("Z")) dateString = dateString.substring(0, 12) + "-0000"; else if (dateString.length() == 18) { String tz = dateString.substring(13); dateString = dateString.substring(0, 13) + tz.substring(0, 2) + tz.substring(3); } synchronized (HMSMZ) { return HMSMZ.parse(dateString); } } }