Here you can find the source of toDate(String isoDate)
Parameter | Description |
---|---|
isoDate | YYYY-MM-DD'T'hh:mm:ss.SSS'Z' |
public static Date toDate(String isoDate)
//package com.java2s; /* Copyright (c) 2015 Magnet Systems, Inc. * * 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.// ww w . j av a2 s. co m */ import java.text.SimpleDateFormat; import java.util.Date; import java.util.EmptyStackException; import java.util.Stack; import java.util.TimeZone; public class Main { private static Stack<SimpleDateFormat> sPool; /** * Convert ISO-8601 UTC Date/Time to Date. * @param isoDate YYYY-MM-DD'T'hh:mm:ss.SSS'Z' * @return */ public static Date toDate(String isoDate) { SimpleDateFormat fmtr; try { fmtr = sPool.pop(); } catch (EmptyStackException e) { fmtr = newInstance(); } try { return fmtr.parse(isoDate); } catch (Throwable e) { // System.err.println("TimeUtil.toDate() failed: "+isoDate); // e.printStackTrace(); // Invalid ISO date format. return null; } finally { sPool.push(fmtr); } } private static SimpleDateFormat newInstance() { SimpleDateFormat fmtr = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); fmtr.setTimeZone(TimeZone.getTimeZone("UTC")); return fmtr; } }