Here you can find the source of getDiffTime(String strDate, int idx)
Parameter | Description |
---|---|
strDate | Date String. |
idx | Index of the +/- character. |
Parameter | Description |
---|---|
ParseException | if <code>strDate</code> is in an invalid format. |
private static int[] getDiffTime(String strDate, int idx) throws ParseException
//package com.java2s; /**/*from ww w . j ava 2 s.co m*/ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved * * The contents of this file are subject to the terms * of the Common Development and Distribution License * (the License). You may not use this file except in * compliance with the License. * * You can obtain a copy of the License at * https://opensso.dev.java.net/public/CDDLv1.0.html or * opensso/legal/CDDLv1.0.txt * See the License for the specific language governing * permission and limitations under the License. * * When distributing Covered Code, include this CDDL * Header Notice in each file and include the License file * at opensso/legal/CDDLv1.0.txt. * If applicable, add the following below the CDDL Header, * with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * $Id: DateUtils.java,v 1.2 2008-06-25 05:53:00 qcheng Exp $ * */ import java.text.ParseException; public class Main { /** * Returns the difference portion of a date string. Array of integer with * the first element defining the hour difference; and second element * defining the minute difference * * @param strDate Date String. * @param idx Index of the +/- character. * @returns the difference portion of a date string. * @throws ParseException if <code>strDate</code> is in an invalid format. */ private static int[] getDiffTime(String strDate, int idx) throws ParseException { // discard the plus/minus char and trailing z char. String strDiff = strDate.substring(idx + 1, strDate.length() - 1); int[] diffArray = new int[2]; int colonIdx = strDiff.indexOf(':'); if (colonIdx == -1) { throw new ParseException("Invalid Date Format", 0); } try { diffArray[0] = Integer.parseInt(strDiff.substring(0, colonIdx)); diffArray[1] = Integer.parseInt(strDiff.substring(colonIdx + 1)); } catch (NumberFormatException nfe) { throw new ParseException("Invalid Date Format", 0); } return diffArray; } }