Java Parse Time parseTime(String timestring)

Here you can find the source of parseTime(String timestring)

Description

Returns a calendar for the given time string.

License

Apache License

Parameter

Parameter Description
timestring the time string

Exception

Parameter Description
ParseException if the time string is not correctly formatted.

Return

a calendar representing the date assumed to be UTC

Declaration

public static Calendar parseTime(String timestring) throws java.text.ParseException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2016 Intuit/*w  ww  .  j a v a2 s. c o  m*/
 *
 * 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.SimpleDateFormat;
import java.util.*;

public class Main {
    /**
     * Returns a calendar for the given time string. The time string should be formatted
     * {@code yyyy-MM-dd'T'hh:mm:ssZ}, where {@code Z} is a literal (and stands for +0000).
     * It is assumed to be in UTC.
     *
     * @param timestring the time string
     * @return a calendar representing the date assumed to be UTC
     * @throws ParseException if the time string is not correctly formatted.
     */
    public static Calendar parseTime(String timestring) throws java.text.ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        Date date = sdf.parse(timestring);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.setTimeZone(TimeZone.getTimeZone("UTC"));
        return cal;
    }
}

Related

  1. parseTime(String t)
  2. parseTime(String text)
  3. parseTime(String time)
  4. parseTime(String time)
  5. parseTime(String time, String formatStrBefore, String formatStrAfter)
  6. parseTime(String timeString, TimeZone timeZone)
  7. parseTime(String token)
  8. parseTimeConfiguration(String time)
  9. parseTimeSpec(String[] spec)