Here you can find the source of convertDatetimeFormat(Date tar_date, String date_format)
public static String convertDatetimeFormat(Date tar_date, String date_format)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static String convertDatetimeFormat(Date tar_date, String date_format) { SimpleDateFormat sdf = new SimpleDateFormat(date_format); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); String formated_date = sdf.format(tar_date); ////////////////////////////////////////////////////////// // Before: 2012-07-23T02:33:09+0000 // After: 2012-07-23T02:33:09+00:00 char last_char = date_format.charAt(date_format.length() - 1); if (last_char == 'Z') { formated_date = formated_date.substring(0, formated_date.length() - 2) + ':' + formated_date.substring(formated_date.length() - 2, formated_date.length()); }//from w w w . j a v a2s . c om ////////////////////////////////////////////////////////// return formated_date; } }