Here you can find the source of formatStringTime(String dateTime)
public static String formatStringTime(String dateTime)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String formatStringTime(String dateTime) { if (dateTime == null || dateTime.equals("")) { return null; }/*w ww . j a v a 2s. c o m*/ String formatToUTC = null; try { long parseLong = Long.parseLong(dateTime); formatToUTC = formatToUTC(parseLong); } catch (NumberFormatException e2) { formatToUTC = null; } if (null != formatToUTC) { return formatToUTC; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = null; try { date = sdf.parse(dateTime); } catch (ParseException e) { sdf = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'"); try { date = sdf.parse(dateTime); } catch (ParseException e1) { return null; } } SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'"); return formatter.format(date); } public static String formatToUTC(long datetime) { return formatLongTime(datetime, "yyyyMMdd'T'HHmmss'Z'"); } public static String formatLongTime(long datetime, String format) { SimpleDateFormat formatter = new SimpleDateFormat(format); return formatter.format(new Date(datetime)); } }