Here you can find the source of parseTimestamp(String timestamp)
public static Date parseTimestamp(String timestamp) throws ParseException
//package com.java2s; //License from project: Open Source License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; public class Main { private static final TimeZone UTC = TimeZone.getTimeZone("UTC"); private static final String DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; private static final String DATE_FORMAT = "yyyy-MM-dd"; private static final int LONG_FORMAT_LENGTH = DATE_TIME_FORMAT.replace("'", "").length(); private static final int SHORT_FORMAT_LENGTH = DATE_FORMAT.replace("'", "").length(); public static Date parseTimestamp(String timestamp) throws ParseException { int length = timestamp.length(); DateFormat format = null; if (length == LONG_FORMAT_LENGTH) { format = new SimpleDateFormat(DATE_TIME_FORMAT); } else if (length == SHORT_FORMAT_LENGTH) { format = new SimpleDateFormat(DATE_FORMAT); } else {/*from ww w .j a v a 2s. c o m*/ throw new ParseException("timestamp has unexpected format: '" + timestamp + "'", 0); } format.setCalendar(new GregorianCalendar(UTC)); return format.parse(timestamp); } }