Here you can find the source of parseTime(String timestring)
Parameter | Description |
---|---|
timestring | the time string |
Parameter | Description |
---|---|
ParseException | if the time string is not correctly formatted. |
public static Calendar parseTime(String timestring) throws java.text.ParseException
//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; } }