Here you can find the source of string2Timezone(String srcFormater, String srcDateTime, String dstFormater, String dstTimeZoneId)
public static String string2Timezone(String srcFormater, String srcDateTime, String dstFormater, String dstTimeZoneId)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class Main { public static String string2Timezone(String srcFormater, String srcDateTime, String dstFormater, String dstTimeZoneId) { if (srcFormater == null || "".equals(srcFormater)) return null; if (srcDateTime == null || "".equals(srcDateTime)) return null; if (dstFormater == null || "".equals(dstFormater)) return null; if (dstTimeZoneId == null || "".equals(dstTimeZoneId)) return null; SimpleDateFormat sdf = new SimpleDateFormat(srcFormater); try {/*from w w w . j a v a 2 s . c o m*/ int diffTime = getDiffTimeZoneRawOffset(dstTimeZoneId); Date d = sdf.parse(srcDateTime); long nowTime = d.getTime(); long newNowTime = nowTime - diffTime; d = new Date(newNowTime); return date2String(dstFormater, d); } catch (ParseException e) { return null; } finally { sdf = null; } } public static int getDiffTimeZoneRawOffset(String timeZoneId) { return TimeZone.getDefault().getRawOffset() - TimeZone.getTimeZone(timeZoneId).getRawOffset(); } public static String date2String(String formater, Date aDate) { if (formater == null || "".equals(formater)) return null; if (aDate == null) return null; return new SimpleDateFormat(formater).format(aDate); } public static String date2String(String formater) { return date2String(formater, new Date()); } }