Here you can find the source of serverTimeStringToLocalDateTime( String serverTimeString, String serverTimeFormat)
public static Date serverTimeStringToLocalDateTime( String serverTimeString, String serverTimeFormat)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { public static Date serverTimeStringToLocalDateTime( String serverTimeString, String serverTimeFormat) { if (serverTimeString.equals("") || serverTimeString.equals(null)) { return null; }//from ww w .j a v a 2s . co m SimpleDateFormat sd = new SimpleDateFormat(serverTimeFormat); sd.setTimeZone(TimeZone.getTimeZone("UTC")); Calendar localCal = Calendar.getInstance(); Date date = new Date(); try { date = sd.parse(serverTimeString); localCal.setTime(date); localCal.setTimeZone(TimeZone.getDefault()); Date dateLocal = localCal.getTime(); return dateLocal; } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }